PCEP Computer Programming and Python Fundamentals Practice Question
Which TWO of the following are valid Python variable names? (Choose two.)
⚠ Common exam trap
The PCEP exam often tests the rule that hyphens are not allowed in variable names (unlike in some other languages or filenames), leading candidates to mistakenly think 'my-var' is valid because it looks like a common naming pattern.
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
✓
_private
(_private) is correct because underscores are allowed in Python variable names, including at the start. Python identifiers can contain letters, digits, and underscores, but must not begin with a digit. A leading underscore is a valid naming convention for internal or private attributes.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
for
Why it's wrong here
Reserved keyword.
- ✗
my-var
Why it's wrong here
Hyphen not allowed.
- ✗
1var
Why it's wrong here
Cannot start with digit.
- ✓
_private
Why this is correct
Leading underscore is allowed.
- ✓
my_var
Why this is correct
Valid, uses underscore.
Go deeper
Related to this question
About these practice questions
Courseiva writes every PCEP question from scratch — 498 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
8 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. Which of the following variable names is valid in Python?
easy- A.1st_value
- ✓ B._private
- C.class
- D.my-var
Why B: (_private) is valid because Python allows variable names to start with an underscore. Identifiers can consist of letters, digits, and underscores, but must not begin with a digit. The underscore is treated as a letter, so _private conforms to Python's naming rules.
Variation 2. Which two of the following are valid Python variable names? (Choose two.)
medium- A.for
- B.2nd_value
- ✓ C.value_2
- D.val-ue
- ✓ E._value
Why C: `value_2` starts with a letter and contains only letters, digits, and underscores, which satisfies Python's identifier rules. Python variable names must begin with a letter or underscore, and can include letters, digits, and underscores; `value_2` meets all these criteria.
Variation 3. Which of the following variable names is valid in Python?
easy- A.1st_value
- ✓ B._count
- C.my-var
- D.class
Why B: (_count) is valid because Python allows identifiers to start with an underscore, and it contains only letters and underscores. Python variable names must start with a letter or underscore, followed by letters, digits, or underscores, and cannot be a reserved keyword.
Variation 4. Which THREE of the following are valid Python variable names?
hard- ✓ A.myVar2
- B.my-var
- ✓ C._myVar
- ✓ D.value
- E.2ndValue
Why A: Python variable names must start with a letter or underscore, and can contain letters, digits, and underscores. 'myVar2' begins with a letter and uses only valid characters, making it a legal identifier.
Variation 5. Which two of the following are valid Python variable names? (Choose two.)
easy- ✓ A.value_2
- B.value-2
- C.2nd_value
- ✓ D._value
- E.for
Why A: Python variable names can contain letters, digits, and underscores, and must start with a letter or underscore. 'value_2' starts with a letter and uses an underscore, making it valid.
Variation 6. Which TWO of the following are valid Python variable names?
easy- ✓ A.my_var2
- B.2nd_var
- ✓ C._myvar
- D.my-var
- E.for
Why A: Python variable names must start with a letter or underscore, and can contain letters, digits, and underscores. 'my_var2' starts with a letter and contains only valid characters, so it is a valid identifier.
Variation 7. Which TWO of the following are valid variable names in Python? (Choose two.)
easy- A.1st_value
- ✓ B.my_var_2
- C.user@name
- ✓ D._private
- E.for
Why B: Variable names in Python must start with a letter or underscore, and can contain letters, digits, and underscores. 'my_var_2' starts with a lowercase letter and uses only underscores and digits, making it a valid identifier.
Variation 8. Which of the following is a valid Python variable name?
easy- A.2var
- ✓ B._var
- C.my-var
- D.var$name
Why B: (_var) is correct because Python variable names must start with a letter or an underscore, and can contain letters, digits, or underscores. The underscore is a valid starting character, making _var a legal identifier.
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.