Tuple unpacking in for loops

前端 未结 6 1386
感动是毒
感动是毒 2020-11-22 16:41

I stumbled across the following code:

for i,a in enumerate(attributes):
   labels.append(Label(root, text = a, justify = LEFT).grid(sticky = W))
   e = Entry         


        
6条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-22 17:04

    [i for i in enumerate(['a','b','c'])]
    

    Result:

    [(0, 'a'), (1, 'b'), (2, 'c')]
    

提交回复
热议问题