xxxxxxxxxx
my_items = ['item1', 'item2', 'item3']
for item in my_items:
print(item)
xxxxxxxxxx
lst = [10, 50, 75, 83, 98, 84, 32]
for x in range(len(lst)):
print(lst[x])
xxxxxxxxxx
def iterate(L):
for index, item in enumerate(L):
print(f'{item} at index: {index}')
iterate([3, 5, 2, 1])
xxxxxxxxxx
# Python list
my_list = [1, 2, 3]
# Python automatically create an item for you in the for loop
for item in my_list:
print(item)
xxxxxxxxxx
# Python3 code to iterate over a list
list = [1, 3, 5, 7, 9]
# Using for loop
for i in list:
print(i)
xxxxxxxxxx
# Python3 code to iterate over a list
list = [1, 3, 5, 7, 9]
# Using for loop
for i in list:
print(i)
xxxxxxxxxx
list_1 = [1, 2, 3, 4]
list_2 = ['a', 'b', 'c']
for i, j in zip(list_1, list_2):
print(i, j)