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}")- A. S [S] S
- B. R [R] R
- C. S [S] R
- 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
- What is printed? python class K: def eq(self, other): return True try: print({K(): 1}) except TypeError: print("TypeError")
- What is printed? python it = iter([1, 2, 3, 4, 5]) print(list(zip(it, it)))
- What is printed? python x = 1 x, y = x + 1, x 10 print(x, y)
- What is printed? python print(any([]), all([]), all([[]]))
- What is printed? python class C: n = 0 def init(self): C.n += 1 @classmethod def total(cls): return cls.n class D(C): pass D(); C(); D()…
- What is printed? python e = 5 try: 1 / 0 except ZeroDivisionError as e: pass try: print(e) except NameError: print("NameError")