← 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()])
- A.[<P object>, <P object>]
- B.[P(), P()]
- C.P() P()
- 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 →