Python Dynamic Type
1. In Python, the type is automatically determined during the run and does not need to be declared in the code in advance.
2. All variables must be explicitly assigned before use, otherwise an error will be generated. #例: Nameerror:name ' A ' is not defined
3. The assignment statement a=3 represents: Create an object representing 3; Create a variable A; Connect the variable to the new object 3. is actually a pointer to the memory space of the object!
4, the above 3rd can be translated as: The variable is a system table element, has a link to the object of the space, the object is allocated a piece of memory, there is enough space to represent the value they represent; a reference is an automatically formed pointer from a variable to an object.
5, object structure--Object header information generally contains two parts: a type identifier; a reference counter that determines whether the object can be recycled
6. Note: The ※※※ type belongs to the object instead of the variable ※※※
In [1]: a=10 in[2]: Print(a) ten in[3]: a= ' spam ' in[4]: Print(a) spamin [5]: a=3.14159 in[6]: print
(a) 3.14159 in
[7]: a+10out[7]: 13.14159 in[8]:
7. When a variable name is given a new object, the space occupied by the original object is reclaimed. #垃圾收集技术: Automatically cleans up objects that reference counters to zero.
8, some objects are modified to share references, and some are modified in situ, need to be differentiated.
9. The operator = = is used to test whether the object has the same value, and the operator is to test whether the two variable names accurately point to the same object. (small integers and strings exist for caching and multiplexing, and may appear to be the same case)
In [8]: x=[1,2,3,4]in [9]: y=[1,2,3,4]in [ten]: x==yout[10]: Truein [All]: X is yout[11]: Falsein [1 2]: x=42 in [+]: y=42 in[+]: x==yout[14]: Truein [[]: X is yout[15]: Truein [+]: x+=1in [+]: Print (x) in[+]: print (y) in[+]: X+=1 in[]: X is yout[20]: False /c16>
++++++ the END ++++++
Python Dynamic Type