首页 > 编程语言 > 详细

python 可变对象和不可变对象

时间:2020-02-10 10:50:54      阅读:57      评论:0      收藏:0      [点我收藏+]

可变对象:地址不变,里面内容可以改变      (list,dict,set)

不可变对象:只要内容改变,必须改变地址  (int,str,float,tuple,frozzenset)

# 可变
list1 = [1, 3, 5, 6, 7, 8]
list2 = list1
list1.remove(1)
print(list2)  # [3, 5, 6, 7, 8]

# 不可变
s = "abcde"
s1 = s
s = "abcdefg"
print(s1)  # abcde

 

python 可变对象和不可变对象

原文:https://www.cnblogs.com/wakey/p/12290027.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!