Valid Variable Names in Python
Which TWO of the following are valid Python variable names? (Choose two.)
Quick Answer
The correct answers are _myVar and var123. Python valid variable names must start with either a letter or an underscore, followed by any combination of letters, digits, or underscores—no spaces, hyphens, or special characters like @ or $ are allowed. This rule is tested directly on the Certified Entry-Level Python Programmer PCEP exam, often in multiple-choice or multiple-select questions that ask you to identify legal identifiers from a list. A common trap is assuming that a variable can start with a digit, like 2ndPlace, or that reserved keywords like for or class are permissible names. To remember the rule, think of the underscore as a secret starter: it’s the only non-letter that can lead a name, just like a silent partner in a business.
⚠ Common exam trap
Python Institute often tests the rule that hyphens are not allowed in variable names, tricking candidates who are used to hyphenated names from other languages like HTML or CSS.
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
✓
var123
(var123) is correct because Python variable names must start with a letter or underscore, and can contain letters, digits, or underscores. 'var123' starts with a letter and contains only valid characters, making it a legal identifier.
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.
- ✓
var123
Why this is correct
Valid: letters and digits.
- ✗
my-var
Why it's wrong here
Hyphen not allowed.
- ✗
1var
Why it's wrong here
Cannot start with a digit.
- ✓
_myVar
Why this is correct
Valid: starts with underscore.
Go deeper
Related to this question
About these practice questions
One of 498 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 →
Same concept, more angles
1 more way 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 TWO of the following are valid Python variable names? (Choose two.)
easy- A.my-var
- ✓ B.my_var
- C.2nd_place
- ✓ D._count
- E.class
Why B: (my_var) is correct because Python variable names can contain letters, digits, and underscores, but must not start with a digit. 'my_var' follows all naming rules: it starts with a letter, uses an underscore, and contains no invalid characters.
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.