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

List & 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.

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.

Cambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones

¿Todo estuvo claro?

Sección 1. Capítulo 4
toggle bottom row

List & 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.

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.

Cambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones

¿Todo estuvo claro?

Sección 1. Capítulo 4
toggle bottom row

List & 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.

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.

Cambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones

¿Todo estuvo claro?

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.

Cambia 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
Cambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
We're sorry to hear that something went wrong. What happened?
some-alt