Apr-10-2023, 07:53 AM
(This post was last modified: Apr-10-2023, 07:53 AM by Gribouillis.)
(Apr-10-2023, 02:27 AM)deanhystad Wrote: Why are you doing "if x is e or x == e"? Can you ever have the check for identity be True when the check for equality is False?I think @quazirfan was only quoting the Python documentation at the point where it explains the behavior of the
in
operator in common containers. Note than in the test x is e or x == e
, the ==
operator is only evaluated if x is not e. I think the documentation means that pointer equality is tried before anything else.documentation for __eq__ Wrote:By default, object implements __eq__() by using is, returning NotImplemented in the case of a false comparison: True if x is y else NotImplemented. For __ne__(), by default it delegates to __eq__() and inverts the result unless it is NotImplemented. There are no other implied relationships among the comparison operators or default implementations
quazirfan Wrote:Am I correct to guess there is no differenceThere is no difference at all.