Valid Python Variable Names: Rules and Common Pitfalls
Which TWO of the following are valid variable names in Python? (Choose two.)
Quick Answer
The correct answers are _count and myVar. In Python, valid variable names must start with either a letter or an underscore, followed by any combination of letters, digits, or underscores—no spaces, hyphens, or special characters like @ or $ are allowed. This question tests your understanding of Python’s identifier rules, a core topic on the Certified Entry-Level Python Programmer PCEP exam, where you must distinguish valid names from common traps like starting with a digit (e.g., 2ndPlace) or using a reserved keyword. A frequent pitfall is forgetting that underscores are fully permitted and even encouraged for special naming conventions, such as _private or __dunder__ methods. To remember the rule, think of the mnemonic “Letter or underscore first, then digits are fine—no symbols, no spaces, no keywords in line.”
⚠ Common exam trap
Python Institute often tests the rule that hyphens are not allowed in variable names, as candidates may confuse them with underscores or assume they are valid like in some other languages.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
_count
(_count) is correct because in Python, variable names can start with an underscore, and underscores are allowed anywhere in the name. Option E (myVar) is correct because it starts with a letter and contains only letters and digits, which is valid. Both follow Python's identifier rules: must start with a letter or underscore, followed by letters, digits, or underscores.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
class
Why it's wrong here
'class' is a reserved keyword.
- ✓
_count
Why this is correct
Underscore is allowed at start.
- ✗
my-var
Why it's wrong here
Hyphen is not allowed; use underscore.
- ✗
2ndPlace
Why it's wrong here
Cannot start with a digit.
- ✓
myVar
Why this is correct
Starts with letter, contains letters and uppercase.
Go deeper
Related to this question
About these practice questions
One of 498 original PCEP practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. Learn why practice questions differ from exam dumps →
Same concept, more angles
1 more way this is tested on PCEP
These questions test the same concept from different angles. Work through them to make sure you can recognise it however the exam phrases it.
Variation 1. Which TWO of the following are valid variable names in Python? (Choose two.)
easy- A.total$
- ✓ B.data1
- C.my var
- ✓ D._count
- E.2nd_place
Why B: 'data1' starts with a letter and contains only letters and digits, which is allowed by Python's identifier rules. Python variable names must begin with a letter (a-z, A-Z) or underscore, and can be followed by letters, digits, or underscores.
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This PCEP practice question is part of Courseiva's free Python Institute certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the PCEP exam.