Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Dataclasses and eq

  • __eq__ is automatically implemented
from shapes import Point

p1 = Point(2, 3, 'left')
print(p1.x)    # 2
print(p1.y)    # 3
print(p1.name) # left

p2 = Point(2, 3, 'left')
p3 = Point(2, 3, 'right')

print(p1 == p2)  # True
print(p1 == p3)  # False

eq are automatically implemented