2.2 Python 保留字符
下面的列表显示了在Python中的保留字。这些保留字不能用作常数或变数,或任何其他标识符名称。
if | not | assert | in | exec | global | False |
elif | for | pass | lambda | is | continue | Ture |
else | while | def | yield | with | as | None |
and | break | return | import | del | class | nonlocal |
or | except | try | from | raise | finally | async |
在Python运行环境中输入以下代码也可以随时查看保留字:
>>> import keyword
>>> print(keyword.kwlist)
输出结果如下:
['False', 'None', 'True', 'and', 'as', 'assert', 'async',
'await', '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']