Python includes six pre-declared constants: True, False, None, __debug__, Ellipsis, and NotImplemented. Despite their common classification as constants, their internal mechanisms and behaviors differ significantly. These inconsistencies are evident in how they are parsed, whether they can be reassigned, and the types of errors generated when attempting to modify them.
True, False, and None are unique in Python as they are keywords, not identifiers. This means they are resolved during the lexical analysis phase, rather than through standard name resolution. A consequence of this design is that expressions like x.True result in a SyntaxError, as the lexer interprets 'True' as a keyword in an invalid context.
The __debug__ constant is a boolean, typically True, but becomes False when Python is run with the -O (optimization) flag. Unlike True, False, and None, __debug__ is an identifier. However, it is unique among identifiers because it cannot be assigned to, either directly (e.g., __debug__ = 67) or as an attribute (e.g., x.__debug__ = 67), both of which raise a SyntaxError. Attempts to delete __debug__ also result in a SyntaxError, though deleting an attribute named __debug__ on an object would raise an AttributeError or NameError, not a SyntaxError.
The error types generated when interacting with these constants are not uniform. While assigning to __debug__ raises a SyntaxError, attempting to access x.__debug__ when x is undefined or lacks the attribute would result in an AttributeError, as it is syntactically valid. This divergence in error reporting for seemingly related operations highlights the distinct internal handling of these pre-declared constants within the Python language.
✨ This summary was generated by AI from the outlets' reporting listed below. It is not independently verified and may contain errors — check the original sources. How BrevFeed works →
One email each morning: the day's tech stories, clustered across outlets and summarized. No account needed.
One email a day. Unsubscribe in one click, any time.
Spend a few minutes, get the whole day. Every topic's top stories in one hands-free rundown — listen, watch, or read the transcript.
▶ Play today's briefNew every morning, and the back catalogue is archived by date.
Python's six pre-declared constants (True, False, None, __debug__, Ellipsis, NotImplemented) demonstrate varied and sometimes unexpected behaviors regarding their lexical parsing, mutability, and error handling. This inconsistency highlights unique design choices within the language's core, affecting how developers interact with these fundamental elements.