Python 中的保留关键字是什么?
pythonserver side programmingprogramming更新于 2025/6/27 15:40:17
保留字(也称为关键字)在语言中具有预定义的含义和语法。这些关键字必须用于开发编程指令。保留字不能用作其他编程元素的标识符,如变量名称、函数等。
以下是 Python 3 中的保留关键字列表
| and | except | lambda | with |
| as | finally | nonlocal | while |
| assert | false | None | yield |
| break | for | not | |
| class | from | or | |
| continue | global | pass | |
| def | if | raise | |
| del | import | return | |
| elif | in | True | |
| else | is | try |
Python 3 有 33 个关键字,而 Python 2 有 30 个。print 已从 Python 2 中删除为关键字,并作为内置函数包含在内。
要检查关键字列表,请在解释器中键入以下命令−
>>> import keyword >>> keyword.kwlist
相关文章
有用资源
python 参考教程 - 该教程包含有关 python 的更多信息:https://www.cainiaomax.com/python/

