Dear Tim,

in Python 2, None is a keyword and True and False are just identifiers. In
Python 3, all of them are keywords.

There is an interesting article by Guido explaining the reason for their
different implementations.

http://python-history.blogspot.com/2013/11/story-of-none-true-false.html

Just ignore the first few introductory paragraphs... probably jump to the
article starting with *"So, after this long detour about built-ins vs.
keywords, back to None."*

Hope this helps,
Peter

On Wed, Jul 22, 2020 at 3:06 AM Tim Chase <python.l...@tim.thechases.com>
wrote:

> I know for ints, cpython caches something like -127 to 255 where `is`
> works by happenstance based on the implementation but not the spec
> (so I don't use `is` for comparison there because it's not
> guaranteed by the language spec). On the other hand, I know that None
> is a single object that can (and often *should*) be compared using
> `is`. However I spent some time reading through the language specs and
> didn't encounter anything about booleans returned from
> comparisons-operators, guaranteeing that they always return The One
> True and The One False.
>
>   x = 3 == 3 # some boolean expression evaluating to True/False
>   y = 4 > 0 # another boolean expression
>   if x is y:
>     print("cool, same as always")
>   else:
>     print("is this ever possible?")
>
> Is there some theoretical world in which that `else` branch could ever
> be hit because the True referenced by x is not the same True
> referenced by y? (assuming non-pathological overriding of dunder
> methods to return true-ish or false-ish values; or at least assuming
> any dunder-overriding is pure standard-library)
>
> In the big picture, this is likely irrelevant and I should just use
> "==" instead, but I got the question stuck in my head and ended up
> bothered that I couldn't disinter an answer from docs.
>
> Thanks,
>
> -tkc
>
>
>
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to