Python's ID () function decryption process

Source: Internet
Author: User
>>> A = 2.5
>>> B = 2.5
>>> C = b
>>> A is C
False

>>> A = 2
>>> B = 2
>>> C = b
>>> A is C
True

Today, when we use the IS function to print a A, a and B are assigned a value of 2.5 and 2, we find that:
>>> A = 2
>>> B = 2
>>> ID (a)
21132060
>>> ID (b)
21132060
>>> A = 2.5
>>> B = 2.5
>>> ID (a)
19622112
>>> ID (b)
29321464

When a, B is 2, the ID is the same, and the time of 2.5 is different, this situation will also appear in string string, that is, when a very short string of a, B and a very short, their ID value is the same, and very long does not;
After that, you can get a simple conclusion: The interpreter did a little bit of optimization on a small int and a very short string, assigning only one object to the same ID.
  • 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.