Python标识符
- 标识符由字母、数字、下划线组成。
- 所有标识符可以包括英文、数字以及下划线(_),但不能以数字开头。
- python中的标识符是区分大小写的。
- 以下划线开头的标识符是有特殊意义的。
- 以单下划线开头(_foo)的代表不能直接访问的类属性,需通过类提供的接口进行访问,不能用"from xxx import *"而导入;
- 以双下划线开头的(__foo)代表类的私有成员;
- 以双下划线开头和结尾的(__ foo __)代表python里特殊方法专用的标识,如__init __()代表类的构造函数。
Python保留字符
所有Python的关键字只包含小写字母。
and | exec | not |
---|---|---|
assert | finally | or |
break | for | pass |
class | from | |
continue | global | raise |
def | if | return |
del | import | try |
elif | in | while |
else | is | with |
except | lambda | yield |