course content

Course Content

Introduction to Python

for Loopfor Loop

If you need to iterate over a certain list of values, you need to use the for loop. This loop doesn't require some predefined variable-counter, although it uses a variable-iterator (which shouldn't be predefined). for loops in Python can iterate over sequence types (that is, for instance, either a list, a tuple, a string, or a dictionary). For instance, you can iterate over string elements.

As you can see, it will iterate over each letter (element) of a string. If you iterate over a list, it will iterate over its elements.

Section 5.

Chapter 4