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]
>>>

发表评论

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

机器人检查 *

分享我的最新文章标题到这里

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据