- 变量的定义
- 变量的命名规则
- 常量
1.变量的定义
变量是为了存储程序运算过程中的中间结果,为了方便日后调用。
官方定义:Variables(变量)are used to store information to be referenced(被日后调用)and manipulated (操作或更改)in a computer program. They also provide a way of labeling data with a descriptive name,so our programs can be understood more clearly by the reader and ourselves. It is helpful to think of variables as containers that hold information. (如果我们把变量看作是一个保存信息的容器是更容易理解的)Their sole (主要的)purpose is to label and store data in memory. This data can then be used throughout (整个)your program.
2.变量的命名规则
(1)要具有描述性。
(2)变量名只能_、数字、字母组成,不可以是空格或特殊字符。(#*?。,)
(3)不能以中文为变量名。
(4)不能以数字开头。
(5)保留字符是不能被使用。
(6)变量名区分大小写。
python中的关键字有:
and elif import return
as else in try
assert except is while
break finally lambda with
class for not yield
continue from or
def global pass
del if raise
3.常量
常量:不变的量 pie = 3.141592653……
在python里所有的变量都是可变的,所以用全部大写的变量名来代表此变量为常量。