我无法理解 for 循环中的行为 .index 方法(Python 3.3.1 (v3.3.1:d9893d13c628, Apr 6 2013, 20:30:21) [MSC v.1600 64 bit (AMD64)] on win32)
L = [e for e in range(11)]
print(L)
for e in L[:]:
print(e, L.index(e))
L[L.index(e)] *= e
print(L)
输出:
>>>
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
0 0
1 1
2 2
3 3
4 2
5 5
6 6
7 7
8 8
9 3
10 10
[0, 1, 16, 81, 4, 25, 36, 49, 64, 9, 100]
>>>
我期待最终列表 [0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100]