python中for循环的几个现象

1.  

运行如下代码

l = [{}, {}, {}]
for k in l:
    k[1] = 1
print(l)

输出为

[{1: 1}, {1: 1}, {1: 1}]
2.

运行如下代码

l = [{}, {}, {}]
for k in l:
    k = {1:1}
print(l)

输出为

[{}, {}, {}]
3.

运行如下代码

l = [1,2,3]
for k in l:
    k = k * 2
print(l)

输出为

[1, 2, 3]

你可能感兴趣的:(#,python基础编程,python)