Skip to main content

Practice ยท 2 of 3

Slotted points

Implement class Point with __slots__ = ('x', 'y'): - constructor takes x, y - instances must NOT support arbitrary attributes (p.z = 1 raises AttributeError) - __eq__/__hash__ consistent: equal points share a hash (define both) - distance_to(other) returns the Euclidean distance (use math.hypot)

Difficulty: advanced

Back to lesson: Practice: Custom Container Practice