Comparisons in Python: the difference between “is” and “==”

Comparing one thing to another is constant in programming. But Python has two ways to do this: == and is. So what’s the difference, anyway?

Let’s give ourselves a class to work with as we see how this all works. A cat, obviously.

class Cat():
def __init__(self, name):
self.name = name

You’ll notice we’ve defined an __eq__ method on our Cat class: this lets us give a…

--

--

Senior Software Engineer | www.adriennedomingus.com

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store