On Python small data pool

What is a small data pool

Small data pool is a way to improve the efficiency of the python, the same value as the fixed data type using the same memory address.

  id for acquiring open space memory address

  A file block, a module, a function, a class, each line of code is a terminal block

  Analyzing two variables is the same memory address

  == determination value is the same on both sides of the equal sign

Data is stored in python by way dictionary

If the same block of code will generate two variables reside in some cases, the first block of code, if it does not then perform a small data block pool

Note: If the "is" determined same "==" necessarily the same

If the "==" same judgment "is" not necessarily the same

Small data pool rules (small data pool supports only str, int, bool)

 

  • Support digital range -5 to 256
  • Multiply string when the overall length of not more than 20
  • Since defined string length is not limited, but must be a string (letters, numbers, underscore)
  • When a special character (except Chinese) definition of resident
  • * 1 is actually a string assignment (two variables use the same memory address assignment)

Rules block

  1. Digital all reside

  2. Multiply the string when the overall length of not more than 20

  3. Custom reside

  4. 1 is actually assigned the string *

  5. Python3.7 string multiply when the total length can not exceed 4096

May be achieved by active resident in built-in module intern Python

Guess you like

Origin www.cnblogs.com/muchengQ/p/11013384.html