首页 > 编程语言 > 详细

[Python] Understand Mutable vs. Immutable objects in Python

时间:2017-12-09 19:14:05      阅读:224      评论:0      收藏:0      [点我收藏+]

In this lesson, you will learn what mutable and immutable objects are, and the difference between them. This understanding will help you determine when objects can be modified in place, and when new objects must be created.

 

List is mutable, which means everytime it returns the same id whether or not you have changed it:

foo = []
id(foo) // same
foo.append(3)
id(foo) // same

 

Immtuable such as string:

str = "Hello"
id(str) // not the same
str = "World"
id(str) // not the same

 

[Python] Understand Mutable vs. Immutable objects in Python

原文:http://www.cnblogs.com/Answer1215/p/8012188.html

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