This series is for yourself to learn Python notes. If there are errors, please correct me.
The basic composition and memory and references of objects
Object
In python, everything is an object. Each object consists of: identity (identity) type (type) value (value)
- The identifier is used to uniquely identify the object, and usually corresponds to the object in the computer memory. Use the built-in function id(obj) to return the identity of the object obj
- Type is used to identify the type of data stored by the object. Type can limit the value range of the object and the operations that can be performed. You can use type(obj) to get the type of the object
- The value represents the information of the data stored in the object, and the value can be printed directly using print(obj)
The essence of the object is: a memory block with a specific value, supporting specific types of related operations.
a = 3
a #3
id(3) #1531372336
type(3) #<class 'int'>
[External link image transfer failed. The source site may have an anti-leech link mechanism. It is recommended to save the image and upload it directly (img-MscD8Osu-1609896253355)(E:\workspace\github\2020\python\images\image-20210105211343886.png) ]
Quote
In python, variables are also called: object references. Because the variable stores the address of the object, and the variable refers to the "object" through the address
Variables are located in: stack memory
Object is located in: heap memory
[External link image transfer failed. The source site may have an anti-leech link mechanism. It is recommended to save the image and upload it directly (img-6lw9z2Aw-1609896253379)(…\images\image-20210105211823292.png)]
Python is a dynamically typed language
variableNot neededDisplay the declaration type, according to the object referenced by the variable, the python interpreter automatically determines the data type
Python is a strongly typed language
Each object has a data type, and only supports operations supported by that type
Search [Zixin] on WeChat or scan the QR code below to make friends and make progress together. The article is continuously updated. At present, I am organizing the study notes of Python hundred battles, and I look forward to more updates in the future.