Bird
0
0

What will be the output of this code?

medium📝 Predict Output Q4 of 15
Python - Variables and Dynamic Typing
What will be the output of this code?
name = 'Alice'
Name = 'Bob'
print(name + ' and ' + Name)
ANameError
BAlice and Bob
CAlice and Alice
DBob and Alice
Step-by-Step Solution
Solution:
  1. Step 1: Understand case sensitivity in Python variable names

    Python treats 'name' and 'Name' as two different variables because variable names are case sensitive.
  2. Step 2: Check the print statement

    It concatenates the value of 'name' ('Alice') with ' and ' and then the value of 'Name' ('Bob').
  3. Final Answer:

    Alice and Bob -> Option B
  4. Quick Check:

    Python variable names are case sensitive = Alice and Bob [OK]
Quick Trick: Variable names differ by case are different variables [OK]
Common Mistakes:
MISTAKES
  • Assuming variable names are case insensitive
  • Expecting error due to similar names
  • Confusing variable values

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes