Getting Started with Python · Class 11 · CBSE · Science Computer Science

Which of the following is a valid Python identifier?

Practice question from Getting Started with Python (Class 11 · CBSE · Science Computer Science), with the correct answer and a step-by-step solution.

easy · MCQ · Q-30D862

Which of the following is a valid Python identifier?

  1. A.2total
  2. B.total-value
  3. C.total_2Correct answer
  4. D.class

Solution

A Python identifier may contain letters, digits, and underscores, but it cannot begin with a digit, contain a hyphen, or be a reserved keyword. Therefore, total_2 is valid.

More from Getting Started with Python

All of Getting Started with Python

Practise more Computer Science

Sign up free for adaptive practice on this chapter, with instant feedback and hints on every question.

Start practising free

Free to start · No credit card needed