Exercises · Q1
Q.Which of the following identifier names are invalid and why?
i. Serial_no.
ii. 1st_Room
iii. Hundred$
iv. Total Marks
v. Total_Marks
vi. total-Marks
vii. _Percentage
viii. True
Tripura TbseTextbookSubjective· 3mImportance★★★★★est
57% · 28/49 Questions
✓ Free question
Six of the eight names break Python's identifier rules — only Total_Marks and _Percentage are valid.
The idea — identifier validity rules. A Python identifier
- may contain only letters (A–Z, a–z), digits (0–9) and the underscore;
- must not begin with a digit;
- must not be a keyword (
True,if,for, …); - allows no spaces or special symbols (dot, hyphen, the dollar symbol, etc.).
Checking each name against those rules:
| # | Identifier | Valid? | Rule broken / satisfied |
|---|---|---|---|
| i | Serial_no. | Invalid | ends with a dot — the period is not allowed inside an identifier (it is the attribute-access operator) |
| ii | 1st_Room | Invalid | starts with a digit |
| iii | Hundred followed by the dollar symbol | Invalid | the dollar sign is a special symbol, never allowed in identifiers |
| iv | Total Marks | Invalid | contains a space — Python would read two separate names |
| v | Total_Marks | Valid | letters and underscore only |
| vi | total-Marks | Invalid | the hyphen is the subtraction operator; Python would parse total - Marks |
| vii | _Percentage | Valid | an identifier may begin with an underscore |
| viii | True | Invalid | True is a reserved keyword (a Boolean literal); keywords can never be identifiers |
Tip
A quick machine check: "Total_Marks".isidentifier() returns True, and keyword.iskeyword("True") returns True — together they encode exactly these rules.
✓Final answer
Invalid: (i) Serial_no. — dot; (ii) 1st_Room — leading digit; (iii) the dollar-sign name — special symbol; (iv) Total Marks — space; (vi) total-Marks — hyphen; (viii) True — keyword. Valid: (v) Total_Marks and (vii) _Percentage.
Unlock everything free for 14 days
- Full step-by-step solutions
- Concept-first explanations
- Methods, shortcuts & mistakes
- PYQ mapping + timed mock tests
Full access for 14 days. No credit card required.