ProgrammingVery hardWipro · Accenture · Capgemini pattern
What does the following Python 3 code print? class Base: def greet(self): return "base" class Mid(Base): def greet(self): return "mid-" + super().greet() class Top(Mid): def greet(self): return "top-" + super().greet() print(Top().greet())
- A. top-mid
- B. base-mid-top
- C. top-mid-base
- D. top-base
Correct answer: C. top-mid-base
Each class's super().greet() calls the next class up the MRO, so the calls chain Top -> Mid -> Base, concatenating all three strings.
More Python Programming questions
- What does the following Python 3 code print? class A: x = 10 def init(self): self.x = 20 a = A() print(a.x, A.x) A.x = 99 print(a.x, A.x)
- What does the following Python 3 code print? class A: count = 0 def init(self): A.count += 1 a1 = A(); a2 = A(); a3 = A() print(A.count)
- What does the following Python 3 code print? print(round(2.5), round(3.5), round(2.675, 2))
- What does the following Python 3 code print? print(0.1 + 0.2 == 0.3)
- What does the following Python 3 code print? print(bool([]), bool({}), bool(()), bool(0.0), bool("0"))
- What does the following Python 3 code print? print([] == False, [] is False)