Wonderful Python objects
In short: Python is a language that can surprise you infinitely and is quite different.
Understanding Python object concepts is a prerequisite for understanding Python data storage. Python uses objects to store data and constructs values of any type to be objects.
1. Python object:
Python objects have three attributes:Id: each object has a unique id. You can view the id of an object through id.Type: the type of the object. It indicates the data type that the object can store and can be viewed through type.Value: the value of OSS data.For example:Python internal implementation mechanism: a = 1. Python first creates an integer object, sets the value of this integer object to 1, and finally assigns this object to variable. A = 2. Create a new integer object in Python, set the object value to 2, and assign the object to variable.Python memory management: each object has a reference counter. when an object is assigned a variable name, the reference timer + 1 is used. When a reference is destroyed, the reference counter-1 is used. When the reference counter is 0, that is, if all references do not exist, the system will destroy this object.
2. Variable names and objects:
Python stores data based on objects. The relationship between variable names and objects is different from that between C/C ++ variable names and memory addresses. In Python, the variable name cannot change the object value. Instead, the variable name points to the new object. In C/C ++, if the variable name is assigned a value again, the corresponding memory address is changed..In Python, a variable name can point to any type of object, and a variable name can be changed to point to a new data object of different types. In C/C ++, a variable name has its specific data type.
3. Python standard type:
The Python language provides standard data types, and data storage is based onObject Mechanism, The above object introduction can deepen our team's understanding of Python data.
- Number
- String
- List
- Tuples
- Dictionary
These Python standard types will be introduced in the subsequent sections.
Python's Object Storage Data mechanism: in essence, Python encapsulates the memory address. The advantage of this encapsulation is that Python can implement automatic memory management and other functions to reduce the burden on developers, the cost is that Python requires more space and performance consumption than C/C ++.