table of Contents
- Description of garbage collection
- Reference counting exercise
- Description of small integers pool concept
- For x = 10, respectively, please use python code print variable values, variable values and the variable data memory type
- For the following codes:
x = 257
y = x
z = 257
Please judge x, y, z values of the variables are the same? x, y, z where the memory address is the same? Please elaborate why the python code?
- Digital Type Description
- Description string type
text
- Brief Python garbage collection:
- Reference count: references to the objects the counter is 0, automatically reclaims the memory
- Clear labeling: fast trigger memory overflow, clear a specific variable names. Resolve the circular reference problem
- Generational Recovery: Depending on the median survival time is divided into different levels, the lower, the higher the level garbage collection sweep frequency
- For the following codes:
x = 10
y = 10
z = 10
del y
10 reference count of how many?
Reference count 2
x = 257
y = x
del x
z = 257
Corresponding to the variable x 257 reference count of how many?
Reference count 2
Brief Python small integer pool concept:
Python implementation int time there is a small integer pool. In order to avoid creating the same value repeated application memory space efficiency brought about by the range [-5,256], small integer objects within that range is to be reused within the scope of the global interpreter, will never be garbage collection recycling.
For
x = 10
, with Python code print variable values, respectively, the memory address of the variable value and the variable data types:
x = 10
print(x)
print(id(x))
print(type(x))
- For the following codes:
x = 257
y = x
z = 257
Please judge x, y, z values of the variables are the same? x, y, z where the memory address is the same? Please elaborate why the python code?
The same value
Pycharm the same memory address, different in cmd
a1 = print(x)
b1 = print(y)
c1 = print(z)
a1 = b1 = c1
a2 = print(id(x))
b2 = print(id(y))
c2 = print(id(z))
a2 =! b2
a2 =! c2
b2 =! c2
Digital Type Description
Integer
Role: that age, number, etc.
Defined way
x = 1 x = int(1)
Float
Role: represents the height, weight, etc.
Defined way
x = 1.0 x = flout(1)
Description string type
Role: table name, gender, appearance, etc.
Defined method:
String is a string of the character string to string together, in a single or double wrapped string of characters triple quotes
name = 'bigb'
sex = "male"
hobby = '''
sing
dance
rap
basketball
'''