Courseiva

PCEP Practice Question: Data Types, Variables, Basic I/O and Operators

Which of the following is a valid Python variable name?

⚠ Common exam trap

Python Institute often tests the misconception that hyphens or special characters like '$' are allowed in variable names, or that digits can start a name, because candidates confuse Python's rules with those of other languages like JavaScript or PHP.

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

✓

_var

(_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.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • ✗

    2var

    Why it's wrong here

    Python identifiers cannot begin with a digit, so 2var raises a SyntaxError at parse time. It is tempting because digits are permitted elsewhere in a name, such as var2, and the token looks like a label. A leading letter or underscore is required instead.

  • ✓

    _var

    Why this is correct

    Underscores are permitted as the first character in Python identifiers, so `_var` satisfies the naming rules. Unlike digits, which cannot start a name, and reserved keywords such as `class`, the underscore prefix is valid. This makes `_var` a legal variable name.

  • ✗

    my-var

    Why it's wrong here

    The hyphen is Python's subtraction operator, so my-var parses as the expression my minus var, not a single identifier. It is tempting because hyphens are common in filenames and URLs. Only letters, digits and underscores are permitted, so my_var would be valid.

  • ✗

    var$name

    Why it's wrong here

    The dollar sign is not a legal Python identifier character, so var$name raises a SyntaxError. It is tempting because $ is valid in shell, PHP and JavaScript identifiers. Python permits only letters, digits and underscores, so varname or var_name would be accepted.

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 →

How Courseiva writes practice questions · Editorial policy

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.