


Description of the location of integer object storage in Python
Mar 16, 2017 pm 05:09 PMIn Python Integer Objects are stored in different locations. Some are pre-allocated memory and are always stored in memory, while others are in use. When opening up space.
The reason for saying this, you can look at the following code:
a = 5 b = 5 a is b # True a = 500 b = 500 a is b # False
It can be seen from the above code that the integer type 5 is has always existed, but the integer type 500 has not always existed.
So which integersare pre-allocated memory addresses?
a, b, c = 0, 0, 0 i = 0 while a is b: i += 1 a, b = int(str(i)), int(str(i)) else: print(i) # 打印 257
As we know from the above, non-negative integers less than or equal to 256 (2**8) are always stored (that is to say, their memory addresses are allocated in advance and do not need to be allocated later)
a = -1 b = -1 a is b # False
And negative numbers will not be pre-allocated.
The above is the detailed content of Description of the location of integer object storage in Python. For more information, please follow other related articles on the PHP Chinese website!

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

What are the advantages and disadvantages of templating?

Google AI announces Gemini 1.5 Pro and Gemma 2 for developers

For only $250, Hugging Face's technical director teaches you how to fine-tune Llama 3 step by step

Share several .NET open source AI and LLM related project frameworks

A complete guide to golang function debugging and analysis
