迭代問題中enumerate()的問題
for t in enumerate(L):
? ?index = t[0]
? ?name = t[1]
? ?print index, '-', name
怎么理解index = t[0] name = t[1] 這兩個賦值?有點搞不懂。
for t in enumerate(L):
? ?index = t[0]
? ?name = t[1]
? ?print index, '-', name
怎么理解index = t[0] name = t[1] 這兩個賦值?有點搞不懂。
2017-05-08
舉報
2017-08-14
t 相當于 tuple 了,因為enumerate,可以讓 標號 與 L的值 對應
2017-05-31
迭代的元素 t 此時是個tuple數組了,當然可以用下標訪問了?
2017-05-26
因為enumerate函數相當于將兩個集合的元素兩兩結合變成一個tuple
例如將List1[1,2]和List2[A,B]組合成[(1,A),(2,B)],其中(1,A)就相當于enumeration中的一個元素
那么此時enumarate中的每一個元素就相當于是一個tuple,而 index和name就相當于是一個tuple中的兩個元素
2017-05-08
打印之后就明白了
print enumerate(L)