4 ms·
None, True, False are singletons and are never constructed again after initilization of the interpreter (and have been keywords in python2). That's why "is" is
by maweki 6y ago
None, True, False are singletons and are never constructed again after initilization of the interpreter (and have been keywords in python2). That's why "is" is always safe.
Small integers, as they are kept around, probably are as well (5 is (2+3) works).
I think what gets dropped during the conversation is, that we've been living with Java doing it this way (is being == and == being .equals) for decades and nobody really complains.
- deleted 6y ago[deleted]
- GoblinSlayer 6y agoI mean why not use == for everything?
- Vaphell 6y ago1. it's a slower check, just like equals() intended for value equality is slower than reference equality == in java. 2. 1 == True and 0 == False, as booleans subclass the int type. On the other hand is distingushes between 1 and True, and 0 and False respectively.