Bird
0
0

What is the output of this code?

medium📝 Predict Output Q13 of 15
Python - Methods and Behavior Definition
What is the output of this code?
class A:
    def first(self):
        print('First')
        self.second()
    def second(self):
        print('Second')

obj = A()
obj.first()
ASecond
BSecond\nFirst
CFirst\nSecond
DFirst
Step-by-Step Solution
Solution:
  1. Step 1: Trace method calls

    Calling obj.first() prints 'First' then calls self.second(), which prints 'Second'.
  2. Step 2: Determine output order

    Output is 'First' then 'Second' on separate lines.
  3. Final Answer:

    First\nSecond -> Option C
  4. Quick Check:

    Method calls run in order called [OK]
Quick Trick: Follow method calls step-by-step to find output order [OK]
Common Mistakes:
  • Assuming second() runs before first()
  • Missing the call to second() inside first()
  • Thinking only first print runs

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes