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?
- A.2total
- B.total-value
- C.total_2Correct answer
- 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
- In Python's interactive mode, what does the prompt >>> generally indicate?
- What will be printed when the following Python code is executed and the user enters 12 on the first line and 3 on the second line? a = inpu…
- Explain the difference between a syntax error and a runtime error in Python, and give one example of each.
- What is the output of the following Python code? x = 7 y = 2 print(x // y, x % y)
Practise more Computer Science
Sign up free for adaptive practice on this chapter, with instant feedback and hints on every question.
Start practising freeFree to start · No credit card needed