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

Course Content

Python Loops Tutorial

List & for LoopList & 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:

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.

How does the code work?


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.

Everything was clear?

Section 1. Chapter 4
toggle bottom row