5 ms·
Or think about it for a moment and realize that it would be True with either precedence if interpreted as expected. Or read the very first part of the linked p
by cjhopman 6y ago
Or think about it for a moment and realize that it would be True with either precedence if interpreted as expected.
Or read the very first part of the linked page that shows:
>>> (True == False) is False
True
>>> True == (False is False)
True
- sbergjohansen 6y agoYes. By the time I realised my second example is redundant, it was already too late to edit the comment. Thanks for clarifying.
- collyw 6y agoWould I be correct in avoiding "is" for any simple data types, and only using it for objects?
- lonelappde 6y agoIntegers are not simple data types in python. https://docs.python.org/2/c-api/int.html#PyInt_FromLong https://docs.python.org/2/c-api/int.html#PyInt_FromLong You'd be correct to use 'is' to mean 'is', and '==' to mean '==', following their definitions.
- sbergjohansen 6y agoSee the comment by lonelappde, but note that the example under discussion here is actually not about `is` vs. `==` either.
- Scarblac 6y agoIt's idiomatic to use it for comparisons with the value `None`, which is a singleton so it's always that one. Other than that, just don't use `is`.