Question

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

Option 4 : 'Q'

Advertisement

Detailed Solution

सही उत्तर 'Q' है।

Key Points
Helpful?
PrepSnapprepsnap.in • Part -A

Question:

What is the output of the following Python code? class P: def f(self): return 'P'; class Q(P): def f(self): return 'Q'; class R(Q): pass; print(R().f()) / निम्नलिखित Python कोड का आउटपुट क्या है?

1.
'P'
2.
'R'
3.
Error
4.
'Q'

Correct Answer: 'Q'

R inherits from Q, which overrides f(); attribute lookup finds Q's f() first and returns 'Q'. / R, Q से विरासत लेता है जो f() को ओवरराइड करता है; lookup में Q का f() पहले मिलता है।

Downloaded from PrepSnap (prepsnap.in)