Variables and memory management:
As with most programming languages, it is important to declare variables before using variables. The Declaration and assignment of variables in Python are performed at the same time, and are declared automatically at the time of the first assignment.
Note, however, that the type of the variable in Python is dynamic, and that both his type and memory occupancy are determined at run time, which is different from the language that is often used, such as C #.
The type of his variable and the amount of memory it occupies are determined at the time of declaration.
Reference count
In order to trace objects in memory, Python uses the simple technique of reference counting, which is to record how many references are in use within Python, and create a reference count when the object is created, but when the object is no longer needed, the reference count of the object becomes 0 o'clock. It is garbage collected.
When an object is created and assigned to a variable, the reference count of the object is set to 1. When the same object is assigned to another variable, the reference count of the object is automatically added to 1.
>>> x = 3.14 #x是第一个引用, when the reference count for this object is 1>>> y = x #创建同一个对象的别名Y, and in fact does not create a new object for Y, but instead adds a reference count of this object to 1
How the object's reference count is incremented:
object is created: x = 3.14
Object created by alias: y = x
Passed to function by argument: FooBar (x)
or become an element of the container object: myList = [' 121 ', X, ' Hxzh ']
One hour python per day (10.12)