Python中的变量命名规则
发布时间:2025-10-09 17:47:09

Python 变量命名规则
1. 要有描述性
2.变量名只能由数字、字母组成,不能由空格或特殊字符组成,如:(#?,¥*~!&)等
3.不能是中文
4.不能从数字开始
相关推荐:Python视频教程
5.不能使用保留字符,如下:
['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']
6.变量区分大小写
常用的命名方法:
phone_number = 13000000000
phoneNumber = 13000000000
