Bird
0
0

What will be the output of the following code?

medium📝 Predict Output Q4 of 15
Python - Variables and Dynamic Typing
What will be the output of the following code?
x = 5
y = x
x = 10
print(y)
A5
B10
CError
DNone
Step-by-Step Solution
Solution:
  1. Step 1: Trace variable assignments

    Initially, x is 5. Then y is assigned the value of x, so y becomes 5. Then x is changed to 10.
  2. Step 2: Understand that y keeps old value

    Changing x after assigning y does not affect y. So y remains 5.
  3. Final Answer:

    5 -> Option A
  4. Quick Check:

    Variables hold values at assignment time [OK]
Quick Trick: Variables keep assigned values unless changed [OK]
Common Mistakes:
MISTAKES
  • Thinking y changes when x changes
  • Confusing assignment with reference
  • Expecting runtime error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes