+ 1
Python
Can you please explain me, how this code works? n=[1,2,3,4,5,6] for i, item in enumerate(n): n[i]*=2 print(n) I can’t understand, why and how we use “item” and “enumerate”
3 odpowiedzi
+ 1
"i" stores a number, the index
And
"item" stores a value, the item
https://www.w3schools.com/JUMP_LINK__&&__python__&&__JUMP_LINK/ref_func_enumerate.asp
+ 2
Cristian Gabriel Mazzulla , thx!
+ 1
I don't know what it would be used for in a list, but in that attached page it uses it for a tuple, which makes more sense since they are not indexed