Is there a way to check if two object contain the same values in each of their variables in python?

If you want the == to work, then implement the __eq__ method in your class to perform the rich comparison.

If all you want to do is compare the equality of all attributes, you can do that succinctly by comparison of __dict__ in each object:

class MyClass:

    def __eq__(self, other) : 
        return self.__dict__ == other.__dict__

Leave a Comment

tech