A point class has both __str__ and __repr__.
class Pt:
def __init__(self, x):
self.x = x
def __str__(self):
return f"P{self.x}"
def __repr__(self):
return f"Pt({self.x})"
pts = [Pt(1), Pt(2)]
print(pts[0], pts, str(pts[1]) + repr(pts[1]))
What does the program print?
Log in to join the discussion.
Loading…