hamburger menu
All Coursesall course arrow
adda247
reward-icon
adda247
    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

    CDP Subject Test 01

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

    EVS Subject Test 01

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

    CTET Paper-I PYP (07 July 2024)

    languageIcon English
    • pdpQsnIcon150 Questions
    • pdpsheetsIcon150 Marks
    • timerIcon150 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
    289k+ students have already unlocked exclusive benefits with Test Prime!
    Our Plans
    Monthsup-arrow