Python - Magic Methods and Operator Overloading
You want to create a class
Book where print(book) shows the title nicely, but repr(book) shows a string that can recreate the object. Which implementation correctly achieves this?class Book:
def __init__(self, title):
self.title = title
def __str__(self):
return f"Book titled '{self.title}'"
def __repr__(self):
# Which line below is correct?
pass