🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← 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"))
  1. A.<main.Book object at ...>
  2. B.Python Basics
  3. C.Book: Python Basics
  4. 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 →