← Quiz: Python OOP: all 15 questions
Quiz: Python OOP · Question 15 of 15
What does this print? (code)
What does this print?
class Book:
def __init__(self, title):
self.title = title
def __str__(self):
return f"Book: {self.title}"
print(Book("Python Basics"))
- A.<main.Book object at ...>
- B.Python Basics
- C.Book: Python Basics
- D.An error
Answer & explanation
Correct answer: Book: Python Basics
print() uses the str method when the class defines one.
Can you get the rest right without peeking?
Take the timed Quiz: Python OOP quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →