PCEP Practice Question: Data Types, Variables, Basic I/O and Operators
Which of the following variable names is NOT valid in Python?
⚠ Common exam trap
Python Institute often tests the rule that variable names cannot start with a digit, and the trap here is that candidates may focus on the underscore or mixed case and overlook the leading digit, mistakenly thinking '2nd_place' is acceptable because it contains letters and underscores.
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
✓
2nd_place
Python variable names cannot begin with a digit. The name '2nd_place' starts with '2', which violates Python's identifier naming rules. Valid variable names must start with a letter (a-z, A-Z) or an 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.
- ✗
My_Var
Why it's wrong here
My_Var is valid: it begins with a letter, and uppercase letters plus underscores are permitted in identifiers. It may look unusual because of the capitalisation, yet Python imposes no lowercase requirement, so it is not the invalid name.
- ✗
_myVar
Why it's wrong here
_myVar is valid: a leading underscore is allowed in Python identifiers and is conventionally used to signal internal or private names. It appears suspect because of the underscore prefix, but that convention carries no syntax restriction.
- ✓
2nd_place
Why this is correct
Python identifiers cannot begin with a digit, so `2nd_place` raises a `SyntaxError` at parse time, satisfying the stem's requirement for an invalid name. Letters, underscores and digits are permitted only after the first character, which must be a letter or underscore.
- ✗
myVar2
Why it's wrong here
myVar2 is a valid Python identifier: it starts with a letter and contains only letters and a digit, with no reserved word conflict. It is tempting to reject it because of the trailing digit, but digits are permitted after the first character.
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 →
Same concept, more angles
4 more ways 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. A developer wants to store a person's age. Which of these variable names is invalid?
easy- A._age
- ✓ B.3rd_age
- C.Age
- D.age_3
Why B: In Python, variable names must start with a letter or an underscore, not a digit. Option B (`3rd_age`) begins with a digit, which violates Python's identifier naming rules and will raise a `SyntaxError` if used in code.
Variation 2. Which of the following is NOT a valid variable name in Python?
easy- A._myvar
- B.myVar2
- ✓ C.2nd_var
- D.my_var
Why C: Python variable names cannot start with a digit. The name '2nd_var' begins with '2', which violates Python's identifier naming rules. Valid variable names must start with a letter (a-z, A-Z) or an underscore (_), and can be followed by letters, digits, or underscores.
Variation 3. Which of the following are valid Python variable names? (Choose two.)
easy- A.for
- ✓ B.data_1
- ✓ C._count
- D.2nd_place
- E.my-var
Why B: (data_1) is correct because Python variable names can contain letters, digits, and underscores, but must not start with a digit. 'data_1' starts with a letter and includes an underscore and digit, all of which are allowed.
Variation 4. Which TWO of the following are valid Python variable names?
medium- ✓ A._name
- B.2name
- C.name$
- D.name-2
- ✓ E.name_2
Why A: Option A, _name, is a valid Python identifier because it begins with an underscore, which is an allowed leading character, and contains only letters and underscores. Option E, name_2, is also valid because it starts with a letter and consists solely of letters, digits, and underscores, with no reserved keyword conflict. Option B, 2name, is invalid because Python identifiers cannot begin with a digit. Option C, name$, is invalid because the dollar sign is not a permitted character in Python identifiers. Option D, name-2, is invalid because the hyphen is not allowed in Python identifiers (it would be parsed as subtraction).
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.