Python变量命名规则,,变量的命名规则1、要


变量的命名规则
1、要具有描述性
2、变量名只能_,数字,字母组成,不可以是空格或者特殊字符(!@#$%^&*~)
3、不能以中文为变量名
4、不能以数字开头
5、变量名区分大小写
6、保留字符不能使用来命名
以下关键字(保留字符)不能声明为变量名
[‘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‘]

例:

student_number=30 #Python官方建议命名规则
studnetNumber=30 #驼峰体

常量
在Python里面没有常量,所有的量都是可变的,
为了区分常量和变量,常量用全部大写的变量名代表此变量为常量

Python变量命名规则

评论关闭