Courseiva

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

Which of the following variable names is valid in Python?

⚠ Common exam trap

Python Institute often tests the misconception that underscores are not allowed or that hyphens are acceptable in variable names, leading candidates to reject _count or accept my-var.

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

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

Answer analysis

Option-by-option breakdown

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

  • ✗

    1st_value

    Why it's wrong here

    An identifier cannot begin with a digit, so 1st_value fails to tokenise as a name and raises a SyntaxError. It is tempting because the leading number reads naturally in English, but Python requires the first character to be a letter or underscore.

  • ✓

    _count

    Why this is correct

    A leading underscore is a legal identifier character in Python, so `_count` satisfies the naming rules. It is not a keyword, starts with a letter or underscore rather than a digit, and contains no illegal symbols, making it a valid variable name.

  • ✗

    my-var

    Why it's wrong here

    The hyphen is parsed as the subtraction operator, so my-var is read as my minus var, not a single identifier; only letters, digits and underscores are permitted. It is tempting because hyphens appear in everyday naming conventions, but Python identifiers cannot contain them.

  • ✗

    class

    Why it's wrong here

    class is a reserved Python keyword, so assigning to it raises a SyntaxError; keywords cannot serve as identifiers. It is tempting because it reads like an ordinary descriptive word, but the language reserves it for class definitions.

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.