list = [0,1,2] for i, v in enumerate(list): print(v+i,end =") #output:024 why? | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
0

list = [0,1,2] for i, v in enumerate(list): print(v+i,end =") #output:024 why?

enumerate

31st Oct 2021, 8:28 AM
Khalif Baby👶
Khalif Baby👶 - avatar
2 Réponses
+ 6
you have 3 indexes so you also have 3 values. indexes: 0 1 2 values : 0 1 2 enumerate goes through an iterable and assigns each value with it's index value in a tuple. PRINT IT OUT IN THE PLAYGROUND. when you use: print(end='') the end paramater assigns a new ending character. (instead of '\n' which is default.) Then you just add the indexes and values and squish em together. 024
31st Oct 2021, 8:50 AM
Slick
Slick - avatar
+ 1
0+0, 1+1, 2+2
31st Oct 2021, 10:43 AM
Shadoff
Shadoff - avatar