for Loop (Python)
A Python for loop repeats a block of code once for each item in a sequence such as a list, string, or range. It is the main way to iterate in Python.
Python
Syntax
for item in iterable:
# do somethingExamples
Python
for fruit in ["apple", "pear"]:
print(fruit)Output:
apple
pearPython
for i in range(3):
print(i)Output:
0
1
2