Courseiva

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

Which TWO of the following are valid Python variable names?

⚠ Common exam trap

Python Institute often tests the rule that hyphens and spaces are invalid in variable names, as candidates may confuse Python with other languages (like Lisp or CSS) where hyphens are allowed, or mistakenly think spaces can be used for readability.

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

✓

_count

Option A, `_count`, is a valid Python variable name because it begins with an underscore, which is an allowed identifier character, and contains only letters and underscores. Option B, `my_var`, is also valid since it starts with a letter and uses only letters and underscores, conforming to Python's identifier rules (letters, digits, and underscores, not starting with a digit). Option C, `var-name`, is invalid because hyphens are not permitted in Python identifiers; the hyphen would be parsed as a subtraction operator. Option D, `2nd_var`, is invalid because an identifier cannot begin with a digit. Option E, `var name`, is invalid because spaces are not allowed in identifiers.

Answer analysis

Option-by-option breakdown

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

  • ✓

    _count

    Why this is correct

    Leading underscores are permitted as the first character of an identifier, so `_count` is a valid Python variable name. It satisfies the stem's requirement by starting with a letter or underscore rather than a digit, and containing only alphanumeric characters and underscores, with no reserved keyword conflict.

  • ✓

    my_var

    Why this is correct

    `my_var` satisfies Python's identifier rules: it begins with a letter, contains only letters, digits and underscores, and is not a reserved keyword. The stem asks for valid variable names, and this identifier is syntactically legal, so it qualifies alongside any other option meeting the same criteria.

  • ✗

    var-name

    Why it's wrong here

    The hyphen is parsed as the subtraction operator, so `var-name` is an expression, not a single identifier. Underscores are the only punctuation permitted inside names. It tempts because hyphens are legal in identifiers elsewhere, such as CSS class names or URL slugs, where no arithmetic parsing occurs.

  • ✗

    2nd_var

    Why it's wrong here

    Identifiers cannot begin with a digit, so '2nd_var' is a syntax error at the tokeniser. Leading digits are valid inside numeric literals and in strings, which is the context where this pattern would be acceptable.

  • ✗

    var name

    Why it's wrong here

    A space is not permitted in an identifier; Python tokenises 'var name' as two separate names, so it cannot be assigned as one variable. Spaces appear in string keys and dictionary access patterns, which is where this form would be legitimate.

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 →

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.