Use of variables in python
Variables and this concept are consistent with variables in equations. Variables in computers are not only numbers, but can be of any data type.
variable name rules
Note that variable names must be uppercase and lowercase English, _
a combination of numbers and numbers, but cannot start with numbers
variable assignment
In python, it =
is an assignment statement. You can assign any data type to a variable. The same variable can be assigned repeatedly, and it can be a variable of different data types.
This kind of language in which the type of the variable itself is not fixed is called a dynamic language , and the corresponding one is a static language . For example, java is a typical static language.
Representation of variables in memory
When we perform assignment operations, such as: foo = "123"
1. A string of 123 is
created in memory 2. A variable of foo is created in memory to point to 123
constant
The so-called constants are immutable variables. Usually all uppercase variable names are used to represent constants such as:
PI=3.1415926
But in fact
PI
it is still a variable, and python has no mechanism to guarantee that it will not be changed, so all uppercase variable names are just idioms.