Encoded data with a small pool

# Character encoding underlying computer binary code are stored 
# and we will arrange the binary code law was born the character encoding 
# initial coding is ACCII coding, he was using bit binary code, consists mainly English and some of the numbers special characters 
# -bit binary code can contain up to 256 kinds of variations 
# China is used GBK GB encoded using 16-bit binary code, and we will bit binary code called a byte 
# to follow uniform standards introduced Unicode unicode encoding 
# unicode character encoding can represent hundreds of millions for memory hard drive is a big waste, so there is now UTF-8, UTF-16 encoding compression unicode 
# UTF-8 in English if it is a number, use ACCII encoding, one byte, if the byte characters is three 
# 00000000 00000000 0,000,000,010,101,010 assume this representation in memory 10, then the first three bytes belongs to a waste of space, whereas in the UTF-8 encoding these fill the byte removed 

# mentioned coding we relate to memory problems, use of default is unicode encoded in python3 
# there are two in python Mechanism, a caching mechanism is a code block, a small data pooling 

# Prerequisites: in the same block. 
#Mechanism content: Python commands executed during the same block of code to initialize the object, checks whether the value already exists, if present, it will be reused. 
# In other words: When execute the same block, encountered command to initialize the object, he will be initialized with the value of this variable is stored in a dictionary, in the face of new variables will first query records in the dictionary , 
# if you have the same record then it will re-use this value before this dictionary. So you example given, when the file executed (same block) will i1, i2 two variables point to the same object, 
# meet their caching mechanism is present only in a memory, namely: the same id. 

# Audience: int (float), str, bool. 
# Specific object :( understand details) 
#    int (a float): any number in the same block of code are multiplexed. 
#    BOOL: True and False 1,0 way will exist in the dictionary, and reuse. 
#    Str: Almost all of the strings will be in line with the caching mechanism, specific provisions are as follows 

s1 = ' sky! WER # & * @ ' 
s2 = ' sky! # * & WER @ ' 
Print (S1 IS S2)
 #Printing is True, provided that, in the same block, if the same block of code, compared with the non-False 


# small pool of data caching mechanism different code blocks, also referred to as small integers caching mechanism, or the like is called dwell mechanism, bloggers believe that as long as you found on the internet these names actually say is a meaning, what is vary. 
# So in the end what is a small data pool? What role does he have? 
# Prerequisites: in a different block. 
# Python automatically integer from -5 to 256 were cached, when you these integer assigned to the variable, and will not re-create the object, but the use of already created the cache object. 
# String python certain rules will reside in the pool in a string to create a copy when you these strings assigned to the variable, and will not re-create the object, but used in a string resides created in the pool good object. 
#    In fact, both the cache or pool resides strings are made of a python optimization, is to string integer, and certain rules of ~ 5-256, in a 'pool' (container, or dictionary) in , regardless of program 
# those variables point to a string or integer within these ranges, then he quoted directly in the 'pool', the implication is that it creates a memory. 

# Audience: int (float), str, BOOL 
# int: So we all know that for integers, the range of small data pool is -5 to 256, if multiple variables are pointing to the same (in this range ) figures, they pointed to in memory is a memory address. 
# String length of 0 or 1, the default mechanism are employed resident (pool small data).
# Length of the string> 1, and contains only lowercase letters, numbers, underline, the default will reside. 
# String obtained by multiplication, two cases. 
# Contains only lowercase letters, numbers, underscores, default resides, and the multiplier to a default dwell 
# contains only uppercase and lowercase letters, numbers, underscores, the total length of <= 20, default dwell 

# specified dwell. 
from SYS Import Intern 
A = Intern ( ' Hello! @ ' * 20 is ) 
B = Intern ( ' Hello! @ ' * 20 is )
 Print (A IS B)

 

Guess you like

Origin www.cnblogs.com/tengx/p/11696636.html