Integers within a certain range. They have only one unique copy.

Source: Internet
Author: User

In python, values of integers less than 256 are assigned to different variables. The addresses of variables in the memory are the same. Values of integers greater than or equal to 256 are assigned to different variables, the address of the variable in the memory is different. I still don't know the reason after thinking about it for a long time.

>>> Q = 255 >>> W = 255 >>>> ID (q) 34227776 >>> ID (W) 34227776 >>>> A = 256 >>>> S = 256 >>>> ID (a) 34227764 >>> ID (s) 34227764 >>>> z = 257 >>>> x = 257 >>>> ID (z) 41770536 >>> ID (x) 41770740

 

Python has the concept of a small integer pool. The number in the small integer pool is a common value (you can also set the parameter range by yourself. The default value is 256 ), python provides this small integer pool to prevent the program from continuously applying to release small integers, thus affecting performance.

To put it bluntly, each number in the small integer pool is an object, which exists with the python process and is irrelevant to the running program. If you want to use a value in its range, it provides it, instead of allocating space to create an object.

Integers within a certain range. They have only one unique copy.

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.