I love the variability of Python's objects

Source: Internet
Author: User
variability : Refers to whether the value of an object can be changed. All Python objects have three properties: type, identifier, value, three properties are almost always read-only, and they are immutable throughout the life of the object. The only exception is the value of the object, and if the value is mutable it is a mutable object and the value immutable is the non-mutable object. immutable object passing values, mutable objects referencing simple types or "scalar" types, including integers and other numeric types, str and Unicode string types, and tuples are immutable. The rest of the dictionaries, lists, classes, classes, etc. are variable >>> mylist1 = [1, ' A ', ['foo', ' bar ']]>>> mylist2 = list (Mylist1) > >> mylist2[0] = 2>>> mylist2[2][0] = ' biz ' >>> print mylist1[1, ' a ', ['biz', ' Bar ']]>& gt;> print mylist2[2, ' a ', ['biz', ' Bar ']] The first two object integers and strings are immutable (pass values), but the third object is a mutable list (referenced), so mylist1 also changed

I love the variability of Python's objects

Related Article

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.