enumerate()

Published onesixx on

인덱스변수없이 루프돌리기

myLetter =  ['A', 'B', 'C']

i=0
for myCh in myLetter:
    print(i, myCh)
    i +=1

for i in range(len(myLetter)):
    myCh = myLetter[i]
    print(i, myCh)
# 0 A
# 1 B
# 2 C

list(enumerate(myLetter))
# [(0, 'A'), (1, 'B'), (2, 'C')]

[(i, myCh) for i , myCh in enumerate(myLetter)]

for i, myCh in enumerate(myLetter): #, start=0):
    print(i, myCh)
# 0 A
# 1 B
# 2 C
Categories: Python Basic

onesixx

Blog Owner

Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x