The following are true:
'None' in keyword.kwlist'None' in builtins.__dict__ # import builtins
My understanding:
- Python evals identifier
xby getting objectbuiltins.__dict__[x] - Python evals keyword
xin a special way that depends on whatxis
This implies that Python evals keyword None to the value of type NoneType (which is interned) without using builtins.__dict__. So why does builtins.__dict__ contain 'None'?
(the same question applies to True and False)
Keywords, in general, aren't evaluated at all. The
keywordmodule just provides, for informational purposes, which words are recognized as special by the Python grammar. In particular,None,True, andFalseare recognized as (hard) keywords so that attempts to redefine them are syntax errors, rather than runtime errors. Also, the list of keywords is not involved in name lookups at all.Otherwise,
Noneis just like any other name that is bound to some value (in this case, the lone value of typetypes.NoneType). In particular, the definition is in the built-in scope, so that it is available from any module without needing to import anything first.builtinsjust reflects those names that are defined in the built-in scope.