PCEP Computer Programming and Python Fundamentals Practice Question
Which TWO of the following are valid variable names in Python?
⚠ Common exam trap
The PCEP exam often tests the rule that hyphens are invalid in variable names (tricking candidates who are used to languages like Lisp or CSS) and that keywords cannot be used as identifiers, even though they look like valid names.
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
✓
total_sum
Option C (total_sum) is valid because Python identifiers may contain letters, digits, and underscores, and this name starts with a letter and uses only those allowed characters. Option E (_count) is valid because a leading underscore is permitted in Python identifiers, and the rest of the name contains only letters. Option A (my-var) is invalid because the hyphen is not allowed in Python identifiers; it is interpreted as a subtraction operator. Option B (2nd_place) is invalid because identifiers cannot begin with a digit. Option D (for) is invalid because 'for' is a reserved Python keyword and cannot be used as a variable name.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
my-var
Why it's wrong here
The hyphen is parsed as the subtraction operator, so `my-var` is read as the expression `my - var`, not a single identifier; only letters, digits and underscores are permitted, and a leading digit is also barred. It tempts because hyphens are legal in many other languages' names, but Python identifiers cannot contain them.
- ✗
2nd_place
Why it's wrong here
Python identifiers cannot begin with a digit, so 2nd_place raises a SyntaxError at assignment. It is tempting because it reads naturally as an ordinal label and contains only letters, digits and an underscore, and it would be valid if the leading digit were removed or replaced with a letter.
- ✓
total_sum
Why this is correct
'total_sum' is valid because it begins with a letter and contains only letters, digits, and underscores, with no spaces or leading digit. Python identifiers are case-sensitive and cannot be keywords, all of which this name satisfies.
- ✗
for
Why it's wrong here
`for` is a reserved keyword, so Python's parser rejects it as an identifier and raises a SyntaxError at assignment. It tempts candidates because it is a short, familiar word used constantly in loop syntax, but keywords are permanently excluded from the identifier namespace; only non-reserved spellings such as `for_` or `loop_for` are valid.
- ✓
_count
Why this is correct
A leading underscore is a legal identifier character in Python, so _count is a valid variable name. It must not begin with a digit and cannot be a reserved keyword, both of which _count satisfies.
Go deeper
Related to this question
About these practice questions
Courseiva writes every PCEP question from scratch — 482 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or 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.