Bird
0
0

Which of the following Python statements correctly assigns the integer 42 to a variable named answer?

easy📝 Syntax Q3 of 15
Python - Variables and Dynamic Typing
Which of the following Python statements correctly assigns the integer 42 to a variable named answer?
Aanswer := 42
Bint answer = 42
Canswer = 42
Dvar answer = 42
Step-by-Step Solution
Solution:
  1. Step 1: Understand Python variable assignment

    Python uses simple assignment with the equals sign (=) without type declarations.
  2. Step 2: Evaluate each option

    answer = 42 uses correct syntax: answer = 42. int answer = 42 is invalid because Python does not require or allow type declarations like int. answer := 42 uses the walrus operator (:=), which is valid in Python 3.8+, but is used for expressions, not standard assignment. var answer = 42 uses var, which is not a Python keyword.
  3. Final Answer:

    answer = 42 -> Option C
  4. Quick Check:

    Simple assignment with = [OK]
Quick Trick: Use = for assignment without type declarations [OK]
Common Mistakes:
MISTAKES
  • Using type declarations like int or var in Python
  • Confusing walrus operator with assignment
  • Using := instead of = for simple assignment

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes