Question

1.
2.
3.
4.
Answer (Detailed Solution Below)

Option 2 : QRP / QRP

Advertisement

Detailed Solution

सही उत्तर QRP / QRP है।

Key Points
Helpful?
PrepSnapprepsnap.in • Part -A

Question:

What is the output of the following Python code? `class P:` / ` def who(self): return "P"` / `class Q(P):` / ` def who(self): return "Q" + super().who()` / `class R(P):` / ` def who(self): return "R" + super().who()` / `class S(Q, R): pass` / `print(S().who())` / निम्नलिखित Python कोड का आउटपुट क्या होगा? `class P:` / ` def who(self): return "P"` / `class Q(P):` / ` def who(self): return "Q" + super().who()` / `class R(P):` / ` def who(self): return "R" + super().who()` / `class S(Q, R): pass` / `print(S().who())`

1.
QPR / QPR
2.
QRP / QRP
3.
RQP / RQP
4.
PQR / PQR

Correct Answer: QRP / QRP

The MRO of S is S → Q → R → P, so `S().who()` calls Q.who, whose `super().who()` resolves to R.who (not P.who), whose `super().who()` reaches P.who — concatenating to "QRP". The trap is assuming `super()` in Q jumps straight to P. / S का MRO है S → Q → R → P, अतः `S().who()` Q.who को बुलाता है, जिसका `super().who()` R.who पर resolve होता है (P.who पर नहीं), जिसका `super().who()` P.who तक पहुँचता है — जुड़कर "QRP" बनता है। जाल यह मानना है कि Q में `super()` सीधे P पर जाता है।

Downloaded from PrepSnap (prepsnap.in)