Lesson 8 of 55
PythonLoops – For
20 minutes
Course progress15%
What you'll learn
Keep these ideas in mind as you work through the lesson.
Lesson 8 of 55
Python20 minutes
Keep these ideas in mind as you work through the lesson.
Python’s for loop iterates over any iterable – lists, tuples, strings, ranges, or generators. It abstracts away manual indexing.
# Iterate over a list
fruits = ['apple', 'banana', 'cherry']
for fruit in fruits:
print(fruit)
# Iterate over a range of numbers
for i in range(3):
print('i =', i)
If you need both the index and the value, use enumerate():
for idx, fruit in enumerate(fruits, start=1):
print(idx, fruit)