在Python中,变量命名有以下规则:
1.变量名只能包含字母、数字和下划线。
2.变量名不能以数字开头。
3.不能使用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。
4.变量名应该是具有描述性的,方便理解。
5.推荐使用小写字母加_的方式命名,如user_name。
6.不建议使用中文命名,不便于维护和阅读。
示例:获取并打印所有Python关键字
领取专属 10元无门槛券
私享最新 技术干货