Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Nested Loops | Loops
Introduction to Python

Nested Loops

Just as you can nest lists within lists or tuples within tuples, you can also loop through elements that are already being looped over. For example, you can loop through a list that contains other lists.

Note

In this code, j represents each element within the nested lists inside the countries list. As the nested loop iterates, j takes on the values of each element in the inner lists, which are then printed.

¿Todo estuvo claro?

Sección 5. Capítulo 8
course content

Contenido del Curso

Introduction to Python

Nested Loops

Just as you can nest lists within lists or tuples within tuples, you can also loop through elements that are already being looped over. For example, you can loop through a list that contains other lists.

Note

In this code, j represents each element within the nested lists inside the countries list. As the nested loop iterates, j takes on the values of each element in the inner lists, which are then printed.

¿Todo estuvo claro?

Sección 5. Capítulo 8
some-alt