标识符
定义:自定义的函数名,变量名,类名
组成:数字、字母、下划线,且不能以数字开头
命名规则:
驼峰命名法:
小驼峰命名法(lower camel case):
第一个单词首字母小写,之后的单词首字母大写。例如:myName
大驼峰命名法(upper camel case):
每个单词的首字母都大写。例如MyName
下划线命名法:
单词之间使用"_"进行连接。例如:my_name
扫描二维码关注公众号,回复:
2229031 查看本文章
关键字
定义:具有特殊功能的标识符
注意:关键字不能作为变量名使用
获取关键字列表(返回列表):
import keyword result = keyword.kwlist print(result, type(result))
运行结果:
['False', 'None', 'True', 'and', 'as', 'assert', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'nonlocal', 'not', 'or', 'pass', 'raise', 'return', 'try', 'while', 'with', 'yield']