ProgrammingHardProduct-company MCQ pattern

What is printed?

What is printed?
class P:
    def __repr__(self): return "R"
    def __str__(self): return "S"

print(P(), [P()], f"{P()!r}")
  1. A. S [S] S
  2. B. R [R] R
  3. C. S [S] R
  4. D. S [R] R

Correct answer: D. S [R] R

print() and f-strings without a conversion use __str__. A list shows its items with __repr__. The !r conversion forces __repr__.

More Python Programming questions

Exams that ask this topic