PCEP Practice Question: Data Types, Variables, Basic I/O and Operators
Which of the following is a valid variable name in Python?
⚠ Common exam trap
Python Institute often tests the rule that hyphens are not allowed in variable names, leading candidates to mistakenly think my-var is valid because it resembles common naming in other languages or file systems.
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. The name _count follows all Python identifier rules: it starts with a letter or underscore, contains only letters, digits, or underscores, and is not a reserved keyword.
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
Hyphens are not permitted in Python identifiers; my-var parses as the expression my minus var, raising NameError. Underscores are the legal separator, so my_var works. The hyphen is tempting because it is common in filenames and CSS, but Python reserves it for subtraction.
- ✗
2nd_place
Why it's wrong here
Identifiers cannot begin with a digit, so the leading 2 makes this a syntax error; Python parses it as a number followed by stray text. It tempts because underscores and digits are otherwise legal inside names, and second_place would be valid — but the first character must be a letter or underscore.
- ✓
_count
Why this is correct
A leading underscore is a legal identifier character in Python, and _count contains no spaces, digits at the start, or reserved keywords. It therefore satisfies Python's naming rules, unlike names beginning with a digit or using punctuation.
- ✗
class
Why it's wrong here
class is a reserved keyword, so assigning to it raises a SyntaxError; keywords can never serve as identifiers. It tempts because it reads like a sensible label for a variable holding a class reference, and a closely related name such as class_name or klass would be perfectly legal.
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.