码迷,mamicode.com
首页 > 编程语言 > 详细

Python 可变对象与不可变对象

时间:2015-05-31 19:56:41      阅读:140      评论:0      收藏:0      [点我收藏+]

标签:

 

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

Python 可变对象与不可变对象

标签:

原文地址:http://www.cnblogs.com/relaxgirl/p/4542538.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!