🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Magic Methods and Properties: all 10 questions

Quiz: Magic Methods and Properties · Question 2 of 10

What does this print? (code)

What does this print?

class P:
    def __repr__(self):
        return "P()"
print([P(), P()])
  1. A.[<P object>, <P object>]
  2. B.[P(), P()]
  3. C.P() P()
  4. D.An error
Answer & explanation

Correct answer: [P(), P()]

Lists show their items using repr.

Can you get the rest right without peeking?

Take the timed Quiz: Magic Methods and Properties quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →