...

/

Deep Down, We're All the Same

Deep Down, We're All the Same

We'll cover the following...

Do Python classes behave “oddly”? Let’s find out!

Press + to interact
class FTW:
pass
print(FTW() == FTW()) # two different instances can't be equal
print(FTW() is FTW()) # identities are also different
print(hash(FTW()) == hash(FTW())) # hashes should be different as well

So, with two objects that don’t compare equal but have the same hash, will there be a hash collision? Not really; there’s another twist to this story.

Press + to interact
print(id(FTW()) == id(FTW()))

How can two objects ...