PCEP Practice Question: Data Types, Variables, Basic I/O and Operators
Which THREE of the following are valid Python variable names?
⚠ Common exam trap
Python Institute often tests the rule that hyphens are invalid in identifiers, tempting candidates who are used to hyphenated names from other contexts, and also tests that leading digits are forbidden, catching those who think numbers can appear anywhere.
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
✓
myVar2
Option A, myVar2, is a valid Python identifier because it starts with a letter and contains only letters and digits, with no reserved characters. Option C, _myVar, is valid because a leading underscore is permitted in Python identifiers and is commonly used to signal internal or private names. Option D, value, is valid because it is a plain sequence of letters that does not collide with any Python keyword. Option B, my-var, is invalid because the hyphen is not allowed in identifiers and would be parsed as subtraction. Option E, 2ndValue, is invalid because Python identifiers cannot begin with a digit.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✓
myVar2
Why this is correct
`myVar2` satisfies Python's identifier rules: it begins with a letter, contains only letters and digits, and avoids reserved keywords. Python permits digits after the first character, so the trailing `2` is valid. It also respects case sensitivity and the prohibition on starting with a numeral, making it a legal variable name.
- ✗
my-var
Why it's wrong here
The hyphen is an operator, so my-var parses as subtraction between two names rather than a single identifier. It is tempting because hyphens appear in ordinary English words and in some other languages' identifiers, and would be valid in a context permitting punctuation, but Python identifiers allow only letters, digits and underscores.
- ✓
_myVar
Why this is correct
_myVar starts with an underscore, which Python permits as the first character of an identifier, followed by valid letters. It is not a keyword, so it satisfies the stem's requirement for a valid variable name.
- ✓
value
Why this is correct
`value` is a valid identifier because it begins with a letter and contains only letters, satisfying Python's naming rules. It is not a reserved keyword, so it can be bound freely. This meets the stem's requirement for a legal variable name.
- ✗
2ndValue
Why it's wrong here
An identifier cannot begin with a digit, so 2ndValue raises a syntax error at parse time. It is tempting because the remaining characters are legal and the name reads naturally, and would be valid if the leading digit were removed or replaced with an underscore or letter.
Go deeper
Related to this question
About these practice questions
This PCEP question is part of Courseiva's 482-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →
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.