class MyClass: def __init__(self, name, age): self.name = name self.age = age def __eq__(self, other): return self.name == other.name and self.age == other.age def __repr__(self): return f"MyClass({self.name}, {self.age})" def __hash__(self): return hash(self.__repr__()) a = MyClass('taha', 30) b = MyClass('taha', 30) c = {a, b} print(c)
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter