Bird
0
0

Which of these is the best variable name for storing a user's age according to Python naming conventions?

easy📝 Conceptual Q2 of 15
Python - Variables and Dynamic Typing
Which of these is the best variable name for storing a user's age according to Python naming conventions?
Auser age
BUserAge
Cuser-age
Duser_age
Step-by-Step Solution
Solution:
  1. Step 1: Understand Python naming conventions

    Python uses snake_case for variable names, which means lowercase letters with underscores between words.
  2. Step 2: Compare options

    user_age uses snake_case correctly. UserAge uses CamelCase, which is usually for class names. Options C and D contain invalid characters (hyphen and space).
  3. Final Answer:

    user_age -> Option D
  4. Quick Check:

    Python variable naming convention = snake_case [OK]
Quick Trick: Use lowercase with underscores for variables in Python [OK]
Common Mistakes:
MISTAKES
  • Using CamelCase for variables
  • Including spaces or hyphens
  • Starting variable names with uppercase letters

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes