PCEP Computer Programming and Python Fundamentals Practice Question
A developer is creating a Python script and needs to assign a value to a variable. Which TWO of the following assignment statements are syntactically valid in Python? (Choose two.)
⚠ Common exam trap
The trap here is assuming that digits can appear anywhere or that hyphens and spaces are allowed, but only letters, digits, and underscores are permitted after the first character.
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_var2 = 10
Valid Python identifiers must start with a letter or underscore, and may contain letters, digits, and underscores. 'my_var = 10' and 'my_var2 = 10' follow these rules. Names starting with a digit, containing a hyphen, or containing a space are invalid and cause SyntaxError.
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 = 10
Why it's wrong here
The hyphen '-' is not allowed in identifiers; it is interpreted as the subtraction operator. Python would try to parse 'my - var = 10', which is invalid because you cannot assign to an expression. This results in a SyntaxError. So this is not a valid assignment.
- ✗
my var = 10
Why it's wrong here
The space between 'my' and 'var' makes this invalid. Python identifiers cannot contain spaces. The interpreter would see 'my' and 'var' as separate tokens, leading to a SyntaxError. So this is not a valid assignment statement.
- ✓
my_var2 = 10
Why this is correct
This is valid: 'my_var2' starts with a letter, contains an underscore and a digit after the first character. Digits are allowed after the first character. The assignment sets my_var2 to 10. This is syntactically correct and demonstrates a common naming pattern.
- ✗
2myvar = 10
Why it's wrong here
This statement is invalid because the variable name starts with a digit. Python identifiers must begin with a letter or underscore. The tokenizer will treat '2' as a numeric literal and 'myvar' as a separate token, causing a SyntaxError. So this is not a valid assignment.
- ✓
my_var = 10
Why this is correct
This is a standard assignment: a valid identifier followed by '=' and an integer literal. 'my_var' starts with a letter and contains an underscore, which is allowed. The statement assigns 10 to the variable. This is syntactically correct and common in Python code.
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.