An additional note, since the other answers answered your question mostly correctly, is that if a class only defines __eq__()
and not __ne__()
, then your COMPARE_OP (!=)
will run __eq__()
and negate it. At that time, your third option is likely to be a tiny bit more efficient, but should only be considered if you NEED the speed, since it's difficult to understand quickly.