Python – Keywords and Identifiers

In this article, we discuss the syntax and usage details of keywords and identifiers in Python.

Python keywords

In Python, keywords are reserved words. It means that we cannot create custom variables or functions or any other identifier with name matching to these keywords. The python programming language defines these keywords for particular purposes.

These are some of the existing python keywords,

  • False
  • await
  • else
  • import
  • pass
  • None
  • break
  • except
  • in
  • raise
  • True
  • class
  • finally
  • is
  • return
  • and
  • continue
  • for
  • lambda
  • try
  • as
  • def
  • from
  • nonlocal
  • while
  • assert
  • del
  • global
  • not
  • with

Essential points about Keywords in Python,

  • Except for None, True and False, all keywords are in lower case.
  • Keywords are case sensitive.
  • You can not create identifiers with a name similar to any existing keyword.
  • There are 33 keywords in python 3.7

Python Identifiers

Identifiers are the names that we choose for custom variables, functions, or classes in a python program. There are specific rules which we need to follow while selecting a name for an identifier in Python,

Rules for choosing Identifier name in Python

  • The identifier can not start with a number.
    • Like 2sample is an invalid identifier.
  • Identifiers can contain letters (a to z or A to Z), numbers (0 to 9), and underscore (_).
    • For example, value_count, dataLoader etc. are some valid identifier names.
  • Python keywords cannot be used as identifiers.
  • Special symbols like !, @, #, $, %, etc. are not allowed as the identifier name in Python.
  • There is no limitation on the length of the identifier in Python.
  • Identifiers are case sensitive, i.e., ‘sample’ & ‘Sample’ are two different identifiers in Python.

We should not use identifier names that start and ends with two underscores like __len__ or _load__ etc. Python uses these kinds of terms to define special variables and methods inside the framework classes. We should avoid using this format to create new identifiers.

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top