Understand where integer objects are stored in Python
Oct 17, 2016 pm 04:35 PMThe storage locations of integer objects in Python are different. Some are pre-allocated memory and are always stored in memory, while others open up space when used.
The reason for saying this, You can take a look at the following code:
1 2 3 4 5 6 |
|
As can be seen from the above code, the integer type 5 always exists, but the integer type 500 does not always exist.
So which integers have pre-allocated memory addresses?
1 2 3 4 5 6 7 |
|
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)
1 2 3 |
|
And negative numbers will not be opened in advance.

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

How Do I Use Beautiful Soup to Parse HTML?

How to Use Python to Find the Zipf Distribution of a Text File

How to Work With PDF Documents Using Python

How to Cache Using Redis in Django Applications

How to Perform Deep Learning with TensorFlow or PyTorch?

Serialization and Deserialization of Python Objects: Part 1

How to Implement Your Own Data Structure in Python
