python中变量的命名

python中变量命名规范:

1.变量命名要有意义,方便于阅读和理解;

2.可以是数字、字母、下划线组合,但是一定不能是由数字作为开头,可以用中文作为变量名,但是应该是没有一个人会用;

3.不能是python的关键字命名,其中python中的关键字都有:['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']。

在python中可以用以下命令来查看关键字:

import keyword
keyword.kwlist

4.可以用驼峰、下划线来命名,但是比较流行的还是下划线命名

猜你喜欢

转载自blog.csdn.net/yehuaner33/article/details/84439702
今日推荐