1items=['baseball','basketball','football']
2for index, item in enumerate(items):
3 print(index, item)
1for index, item in enumerate(items):
2 print(index, item)
3
4#if you want to start from 1 instead of 0
5for count, item in enumerate(items, start=1):
6 print(count, item)
1my_list = [0,1,2,3,4]
2for idx, val in enumerate(my_list):
3 print('{0}: {1}'.format(idx,val))
4#This will print:
5#0: 0
6#1: 1
7#2: 2
8#...
1presidents = ["Washington", "Adams", "Jefferson", "Madison", "Monroe", "Adams", "Jackson"]
2for num, name in enumerate(presidents, start=1):
3 print("President {}: {}".format(num, name))
4
1# Creates two variables; An index (num), and the value at that index (line)
2for num, line in enumerate(lines):
3 print("{0:03d}: {}".format(num, line))
4