A few notes on the Python variable
Python supports a variety of data types, within a computer, you can think of any data as an "object", and variables are used in the program to point to these data objects, the variable is assigned to the data and variables to associate.
- A variable is a reference to a Memory object;
- Variable has no type, object has type;
- Python is a dynamic type language, and at any point in time, an object reference can re-reference a different object (which can be a different data type) whenever needed;
- When an object reference to a data does not exist, Python automatically garbage-collects it;
In Python, if you want to use a variable, you don't need to declare it in advance, you just need to assign a value to the variable when you use it. In particular, it is emphasized that it is necessary to assign a value to a variable as long as it is used .
- In Python, the role of "=" is to bind an object reference to an object in memory
- Assigning a variable x = y is the variable x pointing to the real object, which is what the variable y points to. Subsequent assignment of the variable y does not affect the direction of the variable x.
Type (): View the data type of the object referenced by the variable;
ID (): View the memory address of the object referenced by the variable;
A few notes on the Python variable