How does Python do bitwise operations? Is it from LSB to MSB, or the opposite? And how does Python do operations on numbers with different numbers of bits? For instance, suppose I had:
A = 0000 1000 1111 1001 0101
B = 0110 1010
C = (A & B) is not 0
If Python starts operations from the MSB on each, this will evaluate to True but if it starts operations from the LSB on each, it will evaluate to False.
is not 0will work work as intended (on CPython) is only due to luck. You must use!= 0to have a program that have the correct semantics according to the language. There could be an implementation of python wereCis always false for the simply fact thatis notis comparing identities and not values, independently of the value ofA & B. The documentation is pretty clear about which objects are singletons. They are things likeNone,True,False,Ellipsis,NotImplemented. Numbers are not guaranteed to be singletons.truevalues.isonly withNoneor when you need a sentinel value (in which case you'll have:sentinel = object(); #do stuff; if somethign is sentinel). The other singletons almost never occur in real python code and all other cases require to use==.