Test 0 and false since false is 0

Steve D'Aprano steve+python at pearwood.info
Tue Jul 11 20:50:32 EDT 2017


On Tue, 11 Jul 2017 11:16 pm, Albert-Jan Roskam wrote:

> >>> False == 0
> True
> >>> False is 0
> False
> 
> 
> =====> Just wondering: Is this 'is' test depending on an implementation detail
> of cPython (small ints, I forgot how small 0-255 maybe, are  singletons)?

No. But the test 0 is 0 will be.

True and False are guaranteed singletons: there will only ever be a single
builtin False.

The small ints including 0 *may* be cached, so that they will be singletons. The
definition of "small" will vary from version to version.



-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.




More information about the Python-list mailing list