python for loop with number code example
Example 1: python for loop
# Range:
for x in range(5):
print(x) # prints 0,1,2,3,4
# Lists:
letters = ['a', 'b', 'c']
for letter in letters:
print(letter) # prints a, b, c
# Dictionaries:
letters = {'a': 1, 'b': 2, 'c': 3}
for letter, num in letters.items():
print(letter, num) # prints a 1, b 2, c 3
Example 2: how to make loops in python
for x in range(0, 3):
print("We're on time %d" % (x))
Example 3: how to make a loop in python
x = 0
while True: #execute forever
x = x + 1
print(x)