Python variable,
I. What are variables?
A variable is a memory object that stores data. The stored content can be dynamically changed. Defining a variable is equivalent to applying for an access space object with an address (variable name) to the memory to store data and facilitate data query and computation.
Ii. variable name rules
1. Variable names can only contain letters, numbers, and underscores. The variable name can start with a letter or underscore and cannot start with a number. For example, you can name the variable abc_1, but cannot name it ABC.
2. Variable names cannot contain spaces. You can use underscores to separate multiple words. For example, the variable name My_name is feasible, and the variable name My name will lead to an error.
3. keywords and function names reserved by python cannot be used as variable names. For example, using print as variable names is not allowed.
4. The variable name should be as short and descriptive as possible. It can be expressed by the TUO peak body. The variable name should be as short as possible and accurate as possible.
5. Variable names in python are case-sensitive. For example, Name and name are two different variable names.
3. How to define variables
Defining a variable in python is simple. Because python is a weak type language, defining a variable does not need to declare the variable type. Directly assigning a value to the variable is equivalent to defining a variable, the variable type matches the value type. NOTE: If only one variable is written and no value is assigned, python considers this variable undefined.
For example, >>> name = "Tom" indicates to define a variable named name. The variable value is "Tom" and the variable type is string.
Iv. Constants
In python, there is no syntax for defining constants. It is usually represented by a fully capitalized variable name, which is only a kind of prompting effect, for example, AGE = 22 (essentially a variable ).