SimpleTuts.com

Python For Loop

A for loop in Python iterates over a sequence (such as a list, tuple, or string) and executes a block of code for each element in the sequence.


fruits = ["apple", "banana", "cherry"]
for x in fruits:
  print(x)
                
Python Online Compiler

Using range() function


for x in range(10):
  print(x)
                
Python Online Compiler

range() function with start and step value


for x in range(2, 30, 3):
  print(x)
                
Python Online Compiler