Bird
0
0

What will be the output of this code?

medium📝 Predict Output Q13 of 15
Python - Variables and Dynamic Typing
What will be the output of this code?
name = "Alice"
age = 30
name = "Bob"
print(name, age)
AAlice 30
BBob 30
CAlice 0
DBob 0
Step-by-Step Solution
Solution:
  1. Step 1: Trace variable assignments

    Initially, name is set to "Alice" and age to 30. Then name is reassigned to "Bob".
  2. Step 2: Understand print output

    The print statement outputs the current values of name and age. Since name was changed to "Bob", and age remains 30, the output is "Bob 30".
  3. Final Answer:

    Bob 30 -> Option B
  4. Quick Check:

    Last assignment wins [OK]
Quick Trick: Last value assigned to variable is what prints [OK]
Common Mistakes:
MISTAKES
  • Thinking first assignment stays unchanged
  • Confusing variable names or values
  • Assuming age changes without assignment

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes