What is Identifiers?

A Python identifier is a name used to identify a variable, function, class, module or other object. An identifier starts with a letter A to Z or a to z or an underscore (_) followed by zero or more letters, underscores and digits (0 to 9). An identifier cannot start with a digit. Python does not allow punctuation characters such as @, $, and % within identifiers.

Here are naming conventions for Python identifiers −
  1. Class names start with an uppercase letter.
  2. All other identifiers start with a lowercase letter.
  3. Starting an identifier with a single leading underscore indicates that the identifier is private.
  4. Starting an identifier with two leading underscores indicates a strongly private identifier.
  5. If the identifier also ends with two trailing underscores, the identifier is a language-defined special name.

Rules for writing Identifiers in Python

  • The identifier is a combination of character digits and underscore and the character includes letters in lowercase (a-z), letters in uppercase (A-Z), digits (0-9), and an underscore (_).
  • An identifier cannot begin with a digit. If an identifier starts with a digit, it will give a Syntax error.
  • In Python, keywords are the reserved names that are built-in to Python, so a keyword cannot be used as an identifier - they have a special meaning and we cannot use them as identifier names.
  • Special symbols like !, @, #, $, %, etc. are not allowed in identifiers.
  • Python identifiers cannot only contain digits.
  • There is no restriction on the length of identifiers.
  • Identifier names are case-sensitive.

  • Python Valid Identifiers :-

  • xyz123
  • pqr_de
  • _abc
  • ABC
  • abc

  • Python Invalid Identifiers Example

  • 231xyz
  • xyz@
  • 786
  • for
  • if





  • Previous Next


    Trending Tutorials




    Review & Rating

    0.0 / 5

    0 Review

    5
    (0)

    4
    (0)

    3
    (0)

    2
    (0)

    1
    (0)

    Write Review Here