enumerate
- enumerate
names = ['Foo', 'Bar', 'Baz']
for i in range(len(names)):
print(i, names[i])
print('')
for i, n in enumerate(names):
print(i, n)
0 Foo
1 Bar
2 Baz
0 Foo
1 Bar
2 Baz
Press ← or → to navigate between chapters
Press S or / to search in the book
Press ? to show this help
Press Esc to hide this help
names = ['Foo', 'Bar', 'Baz']
for i in range(len(names)):
print(i, names[i])
print('')
for i, n in enumerate(names):
print(i, n)
0 Foo
1 Bar
2 Baz
0 Foo
1 Bar
2 Baz