Editor settings

General settings

Save settings

Learn to program with Python

For loop with Python lists #

You can use for loops to iterate through the elements of a list and perform various operations on each element. Looping through a list allows you to access and manipulate the data stored in it.

Here's an example of how to write a for loop with a list in Python:

my_list = [1, 2, 3, 4, 5]
for item in my_list:
    print(item)  # print each item

Exercise #

  • Use a for loop so that the variable total is the sum of all the numbers in the list.
Output will be displayed here