PCEP Practice Question: Data Types, Variables, Basic I/O and Operators
A Python developer is reviewing a script that contains several variable declarations. They want to identify which assignments use valid variable names according to Python's naming rules. Which TWO of the following variable names are valid? (Choose two.)
⚠ Common exam trap
The trap here is assuming that any descriptive name is valid, overlooking rules like starting with a digit or using a hyphen, or forgetting that keywords are reserved.
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
✓
my_var
Valid Python variable names must start with a letter or underscore, followed by letters, digits, or underscores, and must not be a reserved keyword. `my_var` and `_private` satisfy these rules, while `2nd_place` starts with a digit, `class` is a keyword, and `my-var` contains a hyphen.
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
`my-var` contains a hyphen (-), which is not allowed in Python identifiers. The hyphen is interpreted as a minus operator, leading to a syntax error if used in an assignment. Valid variable names may include letters, digits, and underscores, but not hyphens.
- ✓
my_var
Why this is correct
`my_var` is a valid Python identifier because it starts with a letter (m), contains only letters, digits, and underscores, and is not a reserved keyword. It follows the naming convention of using lowercase letters with underscores for readability. Therefore, it is a valid variable name.
- ✗
2nd_place
Why it's wrong here
`2nd_place` is invalid because it begins with a digit (2). Python variable names must start with a letter (a-z, A-Z) or an underscore (_). Since it starts with a number, it would cause a syntax error. Thus, it is not a valid identifier.
- ✓
_private
Why this is correct
`_private` is valid because it starts with an underscore, which is allowed. It contains only letters and an underscore, and it is not a keyword. While the leading underscore suggests a private variable by convention, it is syntactically correct and can be used as a variable name.
- ✗
class
Why it's wrong here
`class` is a reserved keyword in Python used to define classes. Keywords cannot be used as variable names. Attempting to assign to `class` would raise a SyntaxError. Therefore, it is not a valid variable name despite being a common English word.
Go deeper
Related to this question
About these practice questions
One of 482 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 →
JA
Written and reviewed by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
Last reviewed September 2026 · checked against the official Python Institute exam blueprint
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.