Bird
0
0

What will be the output of this code?

medium📝 Predict Output Q5 of 15
Python - Variables and Dynamic Typing
What will be the output of this code?
a = 3
b = a
b = b + 2
print(a, b)
A5 5
BError
C3 3
D3 5
Step-by-Step Solution
Solution:
  1. Step 1: Follow variable assignments

    a is 3, b is assigned a's value (3). Then b is updated to b + 2, so b becomes 5.
  2. Step 2: Check values at print

    a remains 3 because it was not changed. b is 5 after addition.
  3. Final Answer:

    3 5 -> Option D
  4. Quick Check:

    Variables are independent after assignment [OK]
Quick Trick: Changing one variable doesn't change others assigned from it [OK]
Common Mistakes:
MISTAKES
  • Assuming a changes when b changes
  • Mixing up variable values
  • Expecting error on reassignment

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes