for loop in py code example
Example 1: python for loop
for i in range(5):
print(i)
for i in range(2, 8):
print(i)
for i in range(2, 10, 2):
print(i)
for i in (['a', 'b', 'c']):
print(i)
Example 2: how to use a for loop in python
a_list = [1,2,3,4,5]
for x in a_list:
print(x)
Example 3: python for loop
a = 10
for i in range(1, 10)
print(i)
Example 4: python for loop
for x in range(5):
print(x)
letters = ['a', 'b', 'c']
for letter in letters:
print(letter)
letters = {'a': 1, 'b': 2, 'c': 3}
for letter, num in letters.items():
print(letter, num)