python for with iterator index code example

Example 1: python for with iterator index

for index, value in enumerate(iterator):
    print(index, value)

Example 2: how to loop the length of an array pytoh

array = range(10)
for i in range(len(array)):
  print(array[i])

Example 3: python enumerate for loop

presidents = ["Washington", "Adams", "Jefferson", "Madison", "Monroe", "Adams", "Jackson"]
for num, name in enumerate(presidents, start=1):
    print("President {}: {}".format(num, name))

Example 4: python array looping

array = ["Var1","Var2","Var3"]
for i in range(len(array)):
  print(array[i])
  
#Output#
#Var1
#Var2
#Var3