Location description of integer object storage in Python

Source: Internet
Author: User
The storage location of Python integer objects is different. some objects are stored in a certain storage all the time, while others open up the reason for saying this when using them, you can store Python integer objects in different locations. some of them are pre-allocated memory, which is stored in the memory all the time. others open up space during use.


For the reason of this sentence, you can look at the following code:

A = 5b = 5a is B # Truea = 500b = 500a is B # False

The code above shows that integer 5 always exists, while integer 500 never exists.


Which integers are pre-allocated memory addresses?

A, B, c = 0, 0, 0i = 0 while a is B: I + = 1 a, B = int (str (I )), int (str (I) else: print (I) # prints 257

As we know, non-negative integers smaller than or equal to 256 (2 ** 8) are stored all the time (that is, their memory addresses are pre-opened and do not need to be distributed later)

A =-1b =-1a is B # False

Negative numbers are not pre-opened.

The above is a detailed description of the location of integer object storage in Python. For more information, see other related articles in the first PHP community!

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.