for

KeywordPython 2.0+Beginner

Starts a loop that iterates over a sequence or iterable

Quick Info

Documentation
Official Docs
Python Version
2.0+

Learn by Difficulty

Quick Example

python
fruits = ["apple", "banana", "cherry"]
for fruit in fruits:
    print(fruit)

# Iterate over a range
for i in range(5):
    print(i, end=" ")
print()

# Iterate over a string
for char in "Python":
    print(char, end="-")
print()

for iterates over any iterable: lists, ranges, strings, dicts, files, and more.

Try in Playground

Tags

languagesyntaxcorecontrol-flowloopiteration

Related Items