Courseiva
Data Types, Variables, Basic I/O and OperatorsmediumMultiple ChoiceObjective-mapped

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

Which of the following variable names is NOT valid in Python?

⚠ Common exam trap

Python Institute often tests the rule that variable names cannot start with a digit, and the trap here is that candidates may focus on the underscore or mixed case and overlook the leading digit, mistakenly thinking '2nd_place' is acceptable because it contains letters and underscores.

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

2nd_place

Python variable names cannot begin with a digit. The name '2nd_place' starts with '2', which violates Python's identifier naming rules. Valid variable names must start with a letter (a-z, A-Z) or an underscore (_), followed by letters, digits, or underscores.

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

    Why it's wrong here

    Valid; uppercase and underscores allowed.

  • _myVar

    Why it's wrong here

    Valid; starts with underscore.

  • 2nd_place

    Why this is correct

    Invalid; starts with a digit.

  • myVar2

    Why it's wrong here

    Valid; digits can appear after the first character.

About these practice questions

Courseiva writes every PCEP question from scratch — 498 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

Same concept, more angles

4 more ways 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. A developer wants to store a person's age. Which of these variable names is invalid?

easy
  • A._age
  • B.3rd_age
  • C.Age
  • D.age_3

Why B: In Python, variable names must start with a letter or an underscore, not a digit. Option B (`3rd_age`) begins with a digit, which violates Python's identifier naming rules and will raise a `SyntaxError` if used in code.

Variation 2. Which of the following is NOT a valid variable name in Python?

easy
  • A._myvar
  • B.myVar2
  • C.2nd_var
  • D.my_var

Why C: Python variable names cannot start with a digit. The name '2nd_var' begins with '2', which violates Python's identifier naming rules. Valid variable names must start with a letter (a-z, A-Z) or an underscore (_), and can be followed by letters, digits, or underscores.

Variation 3. Which of the following are valid Python variable names? (Choose two.)

easy
  • A.for
  • B.data_1
  • C._count
  • D.2nd_place
  • E.my-var

Why B: (data_1) is correct because Python variable names can contain letters, digits, and underscores, but must not start with a digit. 'data_1' starts with a letter and includes an underscore and digit, all of which are allowed.

Variation 4. Which TWO of the following are valid Python variable names?

medium
  • A._name
  • B.2name
  • C.name$
  • D.name-2
  • E.name_2

Why A: Python variable names must start with a letter or an underscore, and '_name' begins with an underscore, which is allowed. The rest of the name consists of letters and underscores, making it a valid identifier per Python's naming rules.

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.