In python, variables can be defined by assignment. You can use the equal sign (=) to assign a value to a variable. The naming of variables follows some rules:
name
and Name
are different variable names. if
, for
, etc. The following are some examples of defining variables:
name = "John"# 字符串类型的变量 age = 25# 整数类型的变量 height = 1.75# 浮点数类型的变量 is_student = True# 布尔类型的变量
You can change the value of the variable at any time as needed, for example:
name = "Alice" age = 30
In this way, the value of variable name
becomes "Alice"
, and the value of variable age
becomes 30
.
The above is the detailed content of How to define variables in python. For more information, please follow other related articles on the PHP Chinese website!