Which of the following is a valid variable name in Python?

Assessment: JAMB UTME - Computer Studies - 2025 Subject: Computer Studies

Question 1 Report

Which of the following is a valid variable name in Python?

Answer Details

Python enforces a small set of rules for naming variables. A valid name must start with a letter or an underscore, may be followed by any combination of letters, digits, and underscores, and must not contain spaces or symbols such as \(\$\) or a hyphen, since Python would interpret a hyphen as a subtraction operator.

Checking each proposed name against these rules: one name is rejected because it contains the symbol \(\$\), which is not permitted in Python identifiers; another is rejected because a hyphen inside a name would be read as subtraction; and another is rejected because it starts with a digit, which Python does not allow since a name beginning with a number could be confused with a numeric literal. The remaining name uses only letters and an underscore and begins with a letter, satisfying every rule for a valid identifier.

When checking whether a variable name is valid in Python, look first at its first character, since that single check eliminates any name starting with a digit, and then scan the rest for forbidden symbols like \(\$\) or a hyphen.

Download The App On Google Playstore

Everything you need to excel in your exams

Green Bridge CBT Mobile App
Personalized AI Learning Chat Assistant
200,000+ Exam Questions Across IGCSE, JAMB, WAEC & NECO
Over 3,900 Lesson Notes
Offline Support - Learn Anytime, Anywhere
Green Bridge Timetable
Literature Summaries & Potential Questions
Track Your Performance & Progress
In-depth Explanations for Comprehensive Learning