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

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

Which of the following is an invalid variable name in Python?

⚠ Common exam trap

The PCEP exam often tests the misconception that hyphens are acceptable in variable names because they appear in other languages (like JavaScript object keys) or in file names, but Python strictly prohibits them in identifiers.

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-var

'my-var' contains a hyphen, which is not allowed in Python variable names. Python identifiers can only include letters, digits, and underscores, and cannot start with a digit. The hyphen is interpreted as a minus operator, making 'my-var' a syntax error.

Answer analysis

Option-by-option breakdown

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

  • _myVar

    Why it's wrong here

    Valid; underscores are allowed at the start.

  • myVar

    Why it's wrong here

    Valid; starts with a letter.

  • my-var

    Why this is correct

    Invalid; hyphens are not allowed in identifiers.

  • my_var

    Why it's wrong here

    Valid; underscores are allowed.

About these practice questions

This PCEP question is part of Courseiva's 498-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

Same concept, more angles

1 more way 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. Which TWO of the following are valid variable names in Python?

easy
  • A._myVar
  • B.my Var
  • C.my-var
  • D.my_var
  • E.2ndPlace

Why A: Options A (_myVar) and D (my_var) are the two correct variable names. Option B (my Var) is invalid because it contains a space, option C (my-var) contains a hyphen which is not allowed, and option E (2ndPlace) starts with a digit.

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.