Previous Next

Python for Loop

A for loop is utilized in Python to loop through a sequence or any other iterable object.

Example:

companies = ["Google", "Apple", "IBM"]
for i in companies:
    print(i)

Output

Google
Apple
IBM

for Loop with range() function

In Python, the range() function creates a series of numbers.

Example:

for i in range(6):
    print(i)

Output

0
1
2
3
4
5
Previous Next