for loop inpython code example
Example 1: python for loop
for num in range(1,10):
print(num)
lst = [1,2,3,4,5]
for item in lst:
print(item)
lst = [1,2,3,4,5]
new_lst = [item for item in lst if i % 2 == 0]
Example 2: python for loop
words=['zero','one','two']
for operator, word in enumerate(words):
print(word, operator)
Example 3: 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