Q:

What does Python's "==" really do

I was working on optimizing the run-time of a program and got to wondering what "==" in Python really does behind the scenes. In particular, I noticed that it can check whether two large "similar" objects are the same really fast. For instance, if you have two strings of length 10 million and they only differ by a character, running == on them takes about as much time as running 2 == 3.

A:

== delegates to the left-hand-side's object's __eq__ special method, if there.  And string objects definitely have one, and it's highly optimized.  So that's really all there is to it...

