为什么 __debug__ 是关键字时不在关键字列表中?
Why is __debug__ not in the keywords list when it's a keyword?
__debug__
是一个内置常量,根据 docs on constants,它似乎不是实现细节。
尝试分配给它时(文档状态不支持)显示以下错误消息:
>>> __debug__ = False
File "<stdin>", line 1
SyntaxError: assignment to keyword
消息看是关键字,但是:
>>> from keyword import kwlist
>>> '__debug__' in kwlist
False
这看起来很奇怪。 None
、True
和 False
也列为常量,包含在 kwlist
中。
为什么 __debug__
不在关键字列表中?
从技术上讲,它不是 Python 语法意义上的关键字。编译器中有一个 specific check 阻止分配给 __debug__
,但就语法而言,__debug__
不是关键字,并且 keyword.kwlist
是从语法.
__debug__
是一个内置常量,根据 docs on constants,它似乎不是实现细节。
尝试分配给它时(文档状态不支持)显示以下错误消息:
>>> __debug__ = False
File "<stdin>", line 1
SyntaxError: assignment to keyword
消息看是关键字,但是:
>>> from keyword import kwlist
>>> '__debug__' in kwlist
False
这看起来很奇怪。 None
、True
和 False
也列为常量,包含在 kwlist
中。
为什么 __debug__
不在关键字列表中?
从技术上讲,它不是 Python 语法意义上的关键字。编译器中有一个 specific check 阻止分配给 __debug__
,但就语法而言,__debug__
不是关键字,并且 keyword.kwlist
是从语法.