arrow
arrow
arrow
Which of the following cannot be used as a valid identifier in Python?
Question

Which of the following cannot be used as a valid identifier in Python?

A.

1stName

B.

Name1

C.

Name_1

D.

FirstName

Correct option is A


In Python, identifiers are names used to identify variables, functions, classes, or other objects. The rules for valid identifiers in Python are:
1. An identifier must start with a letter (A-Z or a-z) or an underscore (_).
2. The rest of the identifier can contain letters, digits (0-9), and underscores.
3. Identifiers cannot start with a digit.
Given the options:
· (a) 1stName: This is invalid because the identifier starts with a digit (1), which is not allowed in Python.
· (b) Name1: This is valid because it starts with a letter and contains a digit, which is allowed.
· (c) Name_1: This is valid because it starts with a letter and contains an underscore and a digit, which are allowed.
· (d) FirstName: This is valid because it starts with a letter and contains only letters.
Important Key Points:
1. Identifiers cannot start with digits. They can only start with letters or underscores.
2. Underscores and digits are allowed after the first character.
Knowledge Booster:
· Identifiers like _variable are valid, as the underscore is considered a valid starting character.
· Python identifiers are case-sensitive, meaning name and Name are treated as different identifiers.

Free Tests

Free
Must Attempt

DSSSB PRT Full Mock - 01

languageIcon English
  • pdpQsnIcon200 Questions
  • pdpsheetsIcon200 Marks
  • timerIcon120 Mins
languageIcon English
Free
Must Attempt

Educational Psychology & Pedagogy - 01

languageIcon English
  • pdpQsnIcon20 Questions
  • pdpsheetsIcon20 Marks
  • timerIcon15 Mins
languageIcon English
Free
Must Attempt

DSSSB PRT PYP Held on 7th March 2022 Shift 1

languageIcon English
  • pdpQsnIcon200 Questions
  • pdpsheetsIcon200 Marks
  • timerIcon120 Mins
languageIcon English
test-prime-package

Access ‘EMRS PGT’ Mock Tests with

  • 60000+ Mocks and Previous Year Papers
  • Unlimited Re-Attempts
  • Personalised Report Card
  • 500% Refund on Final Selection
  • Largest Community
students-icon
368k+ students have already unlocked exclusive benefits with Test Prime!
Our Plans
Monthsup-arrow