Bird
0
0

You want to create a dictionary where keys are variable names and values are their descriptions. Which of these variable names is invalid and should be excluded?

hard📝 Application Q8 of 15
Python - Variables and Dynamic Typing
You want to create a dictionary where keys are variable names and values are their descriptions. Which of these variable names is invalid and should be excluded?
variables = ['first_name', 'last-name', '_age', '3rd_place']
A'first_name' only
B'last-name' and '3rd_place'
C'_age' only
DAll are valid
Step-by-Step Solution
Solution:
  1. Step 1: Check each variable name for validity

    'first_name' and '_age' are valid names. 'last-name' contains a hyphen which is invalid. '3rd_place' starts with a digit which is invalid.
  2. Step 2: Identify invalid names

    Both 'last-name' and '3rd_place' are invalid and should be excluded.
  3. Final Answer:

    'last-name' and '3rd_place' -> Option B
  4. Quick Check:

    Hyphens and starting digits are invalid in variable names [OK]
Quick Trick: Exclude names with hyphens or starting digits [OK]
Common Mistakes:
MISTAKES
  • Including names with hyphens
  • Allowing variable names starting with digits
  • Assuming underscore prefix is invalid

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes