Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
List & for Loop | The for Loop
Python Loops Tutorial
course content

Course Content

Python Loops Tutorial

Python Loops Tutorial

1. The for Loop
2. The while Loop
3. Nested Loops

bookList & for Loop

We can employ various data structures when working with loops. So far, we've covered strings, and now we'll explore working with a list of numbers.

Examine the following code:

12345
numbers = [2, 3, 4, 5, 6, 7, 8, 11] # Printing all elements of the list for i in numbers: print(i)
copy

How does the code work?

To work with a decreasing list, you can utilize the reversed() function. This function allows you to reverse the order of elements in a list, effectively turning it into a decreasing list.

12345
numbers = [2, 3, 4, 5, 6, 7, 8, 11] # Printing all elements of the reversed list for i in reversed(numbers): print(i)
copy

How does the code work?

Task

To sum the elements inside the list, follow these steps:

  1. Configure the for loop to operate on the numbers, utilizing i as an element of the list.
  2. Calculate the sum by adding elements to the counter within the loop.
  3. Print the value of the counter after the loop has completed.

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 1. Chapter 4
toggle bottom row

bookList & for Loop

We can employ various data structures when working with loops. So far, we've covered strings, and now we'll explore working with a list of numbers.

Examine the following code:

12345
numbers = [2, 3, 4, 5, 6, 7, 8, 11] # Printing all elements of the list for i in numbers: print(i)
copy

How does the code work?

To work with a decreasing list, you can utilize the reversed() function. This function allows you to reverse the order of elements in a list, effectively turning it into a decreasing list.

12345
numbers = [2, 3, 4, 5, 6, 7, 8, 11] # Printing all elements of the reversed list for i in reversed(numbers): print(i)
copy

How does the code work?

Task

To sum the elements inside the list, follow these steps:

  1. Configure the for loop to operate on the numbers, utilizing i as an element of the list.
  2. Calculate the sum by adding elements to the counter within the loop.
  3. Print the value of the counter after the loop has completed.

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 1. Chapter 4
toggle bottom row

bookList & for Loop

We can employ various data structures when working with loops. So far, we've covered strings, and now we'll explore working with a list of numbers.

Examine the following code:

12345
numbers = [2, 3, 4, 5, 6, 7, 8, 11] # Printing all elements of the list for i in numbers: print(i)
copy

How does the code work?

To work with a decreasing list, you can utilize the reversed() function. This function allows you to reverse the order of elements in a list, effectively turning it into a decreasing list.

12345
numbers = [2, 3, 4, 5, 6, 7, 8, 11] # Printing all elements of the reversed list for i in reversed(numbers): print(i)
copy

How does the code work?

Task

To sum the elements inside the list, follow these steps:

  1. Configure the for loop to operate on the numbers, utilizing i as an element of the list.
  2. Calculate the sum by adding elements to the counter within the loop.
  3. Print the value of the counter after the loop has completed.

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

We can employ various data structures when working with loops. So far, we've covered strings, and now we'll explore working with a list of numbers.

Examine the following code:

12345
numbers = [2, 3, 4, 5, 6, 7, 8, 11] # Printing all elements of the list for i in numbers: print(i)
copy

How does the code work?

To work with a decreasing list, you can utilize the reversed() function. This function allows you to reverse the order of elements in a list, effectively turning it into a decreasing list.

12345
numbers = [2, 3, 4, 5, 6, 7, 8, 11] # Printing all elements of the reversed list for i in reversed(numbers): print(i)
copy

How does the code work?

Task

To sum the elements inside the list, follow these steps:

  1. Configure the for loop to operate on the numbers, utilizing i as an element of the list.
  2. Calculate the sum by adding elements to the counter within the loop.
  3. Print the value of the counter after the loop has completed.

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Section 1. Chapter 4
Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
some-alt