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

Contenido del Curso

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?

Tarea

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 desktopCambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 1. Capítulo 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?

Tarea

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 desktopCambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 1. Capítulo 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?

Tarea

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 desktopCambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

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?

Tarea

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 desktopCambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
Sección 1. Capítulo 4
Switch to desktopCambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
some-alt