Hacker News new | ask | show | jobs
by sbergjohansen 2235 days ago
To see that this is not about precedence, evaluate the following:

  >>> True == False is False
  False
  >>> False == True is False
  False
1 comments

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
Would I be correct in avoiding "is" for any simple data types, and only using it for objects?
Integers are not simple data types in python. 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.

It'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`.

See the comment by lonelappde, but note that the example under discussion here is actually not about `is` vs. `==` either.
Yes. By the time I realised my second example is redundant, it was already too late to edit the comment. Thanks for clarifying.