Python Keywords and Identifiers

Suraj Yadav
3 min readMar 29, 2022

--

Image by author

In this article, you will learn about what keywords and identifiers are and how to use them.

Python Keywords:

1. Keywords are the reserved words in python

2. We can’t use a keyword as a variable name, function name, or any other identifier

3. Keywords are case sensitive

There are 35 keywords in Python. All the keywords except True, False and None are written in lower-case letters.

The statement import keyword is used to import the keyword class. The statement print(keyword.kwlist) prints the list of the available keywords in Python.

Wait! Don’t try to figure out the meaning of these words and where to use them when coding at the first sight. For now, just remember that these are the keywords in Python and they are case sensitive. That’s enough for now.

Here is the list of all the keywords you are to use with Python coding.

Image from medium.com

Note: If we want to access any method/variable of a class, we first have to import the class. If you want to use any one of these 35 keywords in your code, you need not import the keyword module. You can directly use them.

Identifier:

The identifier is the name given to entities like class, functions, variables, etc. in Python. It helps differentiate one entity from another.

Rules for writing an Identifier:

  1. Identifiers can be a combination of lowercase letters (a-z) or uppercase letters (A-Z) or digits (0–9) or an underscore (_).
  2. An identifier cannot begin with a digit but can contain digits in the middle. (ie., the first character in the identifier should never be a digit and we can use digits anywhere else in the identifier except the first position.)
  3. Keywords cannot be used as identifiers. Below is an example

Here finally is keywords and we are using it as an identifier, this is why we are getting a syntax error.

4. Apart from underscore (_), no special character should be used in an identifier. Below is an example shown.

5. An identifier can be of any length.

Here we have come to the end of this part. In the end, what you have to keep in your mind is that keywords are the reserved words in Python and identifiers are the names that you can put for the variables, classes, functions, etc.

I hope you have found the article useful.

--

--