python 元组的赋值

元组的赋值比较特殊,需要特别注意,见下面的例子:
(红色部分的两种赋值方法,得到的结果是不一样的)
ActivePython 2.6.6.18 (ActiveState Software Inc.) based on
Python 2.6.6 (r266:84292, Jan 7 2011, 13:16:36) [MSC v.1500 32 bit (Intel)] on
win32
Type “help”, “copyright”, “credits” or “license” for more information.
>>> x=[1,2,3]
>>> y=x
>>> print x
[1, 2, 3]
>>> y.remove(3)
>>> print x
[1, 2]
>>> x=[1,2,3]
>>> y=x[:]
>>> y.remove(3)
>>> print x
[1, 2, 3]
>>>

发表评论

电子邮件地址不会被公开。 必填项已用*标注

机器人检查 *