2018年11月14日 星期三

[python] List are mutable.


a=[1,2,3,4,5]
b=a

print(a is b)
b[0]='X'
print(a is b)
print(a,b)

output>>
True
True
['X', 2, 3, 4, 5] ['X', 2, 3, 4, 5]


lists are mutable. To use 'b=a' can create a new list easily. At the same time, it will change the value inside.

沒有留言: