osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Test 0 and false since false is 0


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.