Python mutable objects and immutable objects

Source: Internet
Author: User

You can see here: http://thomaschen2011.iteye.com/blog/1441254

    • Immutable object: Int,string,float,tuple
    • Variable object: list,dictionary

Mutable objects and immutable objects in Python, like literal meaning, mutable objects can be changed once they are created, but the address does not change, that is, the variable points to the original object. Immutable objects, in contrast, cannot be changed after they are created, and if changed, the variable points to a new object.
Give me a chestnut:

>>> s ='ABC' #Immutable Objects>>>ID (s)3072200191 >>> S + ='D'3072200325 >>> L = ['a','b','C']#mutable Objects>>>ID (L)3072200074 >>> L + ='D'>>>ID (L)3072200074

It is found that adding elements to an immutable object causes the variable to point to the object address to change, and the variable object address does not change.

Python built-in object, in Variable object list, Dict. Immutable Object str, int., tuple, float

D

Python mutable objects and immutable objects

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.