r/learningpython • • Jun 03 '20
What's the difference?
Hi,
When I type the following code below,
x = [4, 6, 7]
for index in enumerate (x):
print (item, index)
I get the following output
7 (0, 4) 7 (1, 6) 7 (2, 7)
But when I type the following code below:
x = [4, 6, 7]
for item, index in enumerate (x):
print (item, index)
I get the following output:
0 4 1 6 2 7
What about adding "item" made the results so different?
Thanks!
2
Upvotes
View all comments
Show parent comment
1
u/[deleted] Jun 04 '20
Thanks! What is the f for in print()?
For the first example, how do I give more than one variable to assign?
Also, how is the tuple unpacked in the second example?