Python for Loops: The Pythonic Way
Watch Now This tutorial has a related video course created by the Real Python team. Watch it together with the written tutorial to deepen your understanding: For Loops in Python (Definite Iteration)
Python’s for
loop allows you to iterate over the items in a collection, such as lists, tuples, strings, and dictionaries. The for
loop syntax declares a loop variable that takes each item from the collection in each iteration. This loop is ideal for repeatedly executing a block of code on each item in the collection. You can also tweak for
loops further with features like