Python Learning note Eight--dynamic type

Source: Internet
Author: User

One. Variables, objects, references:

1. Variables:

2. Object: Contains a header information, the following two parts of the content

A. The data type of the object,

B. Reference counter: Records the number of current references to the object, and once the counter is zeroed, the object's memory space is reclaimed.

3. Reference: A pointer between an associative variable and an object,

A=3

Two. Shared references, newly created objects:

1. A=3

B=a

A= ' spam '

A changes, B is also equal to 3, because the object that B points to does not change, and B's pointer does not change.

2. A=3

B=a

A=a+2

b What's the situation?

Python assigns a new value to a variable, does not change the original object, is to recreate an object, and then point the new object pointer to the variable, the old object's counter will remove a reference

Three. To share the app, modify the object in place:

1. l1=[2,3,4]

L2=l1

L1[0]=24

L1 and L2 are changed to [24,3,4]

2. l1=[2,3,4]

l2=l1[:]

L1[0]=24

L1 is [24,3,4]l2=[2,3,4], because l1[:] is a copy-only object and does not create a reference.

Four. Shared references and equality:

1. ' = = ': Determine whether the value of two objects is the same

2. ' Is ': Determine the identity of two objects, i.e. whether two variables point to the same object

Python Learning note Eight--dynamic type

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.