Python基础python变量

python中标识符又称为变量。

变量定义的规则:

变量名只能是 字母、数字或下划线的任意组合

变量名的第一个字符不能是数字

以下关键字不能声明为变量名

['and', 'as', 'assert', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'exec', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'not', 'or', 'pass', 'print', 'raise', 'return', 'try', 'while', 'with', 'yield']

python是大小写敏感的。

约定:

不准使用中文。

不准使用歧义单词,如class_

在python中尽量不要随便使用以下划线开头的标识符。

常量

一但赋值就无法改变值的标识符。

python中无法定义常量

(但是,我们可以定义一个变量,把它当做常量。定义时变量名要大写)

posted @ 2017-12-14 10:38  平凡の路  阅读(110)  评论(0编辑  收藏  举报