Categories
python

for loop in python

In this tutorial, we will learn about for loop in python. We can iterate an array using for loop.

Syntax

for seq_val in sequence:
  body

Iterate array

cars = ["Honda", "Toyota", "Hyundai"]
for car in cars:
    print(car)

Output

Honda
Toyota
Hyundai

for loop using range

cars = ["Honda", "Toyota", "Hyundai"]
for i in range(len(cars)):
    print(cars[i])
Honda
Toyota
Hyundai

for loop with custom start value

cars = ["Honda", "Toyota", "Hyundai"]
for i in range(2, len(cars)):
    print(cars[i])

Output

Hyundai

Related Articles