变量名的命名规范
1、由数字、字母、下划线组成
2、不能以数字开头
3、不能是#关键字(keyword.kwlist) - python已经定义好的,有自己特殊功能的
4、区分大小写。
5、见名知意。
示例如下:
1、由数字、字母、下划线组成:
handsome_01_ = '我每天对着镜子说三遍"我很帅"!'
handsome = '我每天对着镜子说三遍"我很帅"!'
Pretty = '桥边的姑娘'
PRETTY =''桥边的姑娘''
cute = '我是很的可爱'
2、不能以数字开头:
99sd = 1
^
SyntaxError: invalid syntax
99_01_sd = 1
^
SyntaxError: invalid decimal literal
3、不能是#关键字(keyword.kwlist) - python已经定义好的,有自己特殊功能的
None = 1
print(None)
# None = 1
^
# SyntaxError: cannot assign to None
True = 1
print(True)
# True = 1
^
# SyntaxError: cannot assign to True
查看所有的关键字:help("keywords")
Here is a list of the Python keywords. Enter any keyword to get more help.
False break for not None class from or True continue global pass __peg_parser__ def if raise and del import return as elif in try assert else is while async except lambda with await finally nonlocal yield
4、区分大小写
PRETTY = '桥边的姑娘很靓'
pretty = '桥边的姑娘很靓+10000'
PRETTY = '桥边的姑娘很靓'
print(preTTY)
# 若不区分大小写则会报错:如下
# NameError: name 'preTTY' is not defined
5、见名知意。
money = 100
apple = "苹果"
age = "年龄"
city = '电话'
注释
#
Ctrl + /
三个单引号 '''我每天都对着镜子说,我很帅。。。'''
三个双引号"""我每天都对着镜子说,我很帅。。"""