Python 可变对象与不可变对象
1、
不可变(immutable):int、字符串(string)、float、(数值型number)、元组(tuple)
可变(mutable):字典型(dictionary)、列表型(list)
>>>person=['name',['saving',100]]
>>>ly=person[:]
>>> zhuzhu=list(person) >>> zhuzhu ['name', ['saving', 100.0]] >>> [id(x)for x in person ,ly,zhuzhu] [4539621960, 4539684984, 4539685560] >>> ly[0]='ly' >>> ly ['ly', ['saving', 100.0]] >>> zhuzhu ['name', ['saving', 100.0]] >>> zhuzhu[0]=['zhuzhu'] >>> zhuzhu [['zhuzhu'], ['saving', 100.0]] >>> zhuzhu[1][1]=40 >>> zhuzhu [['zhuzhu'], ['saving', 40]] >>> ly ['ly', ['saving', 40]] >>> ly[1][0]='newsaving' >>> ly ['ly', ['newsaving', 40]] >>> zhuzhu [['zhuzhu'], ['newsaving', 40]]
参考链接:
1、http://blog.csdn.net/taohuaxinmu123/article/details/39008281