python foreeach loop code example
Example 1: python for loop
for num in range(5): # range(5) generates numbers from 0 to 4(inclusive)
print(num) # for each iteration num has value assigned by range function
Example 2: python for loop
for x in range(10):
print(x)
// output: 1,2,3,...,10
for x in range(10, 20, 2):
print(x)
// output: 10, 12, 14, 16, 18, 20
list = [2, 3, "el"]
for x in list:
print(x)
// output: 2, 3, "el"
for _ in range(10):
print("a");
// Do the loop without using index