Machine Learning in Cloud

Machine Learning in Cloud

Python Keywords and Identifiers

This sections explains keywords (reserved words in Python) and identifiers (names given to variables, functions, classes, etc.).

Python Keywords

There are 35 keywords in Python 3.8.2. The number of keywords varies based on the Python version.

  • Keywords are the reserved words in Python.
  • Keyword cannot be used as a variable name, function name or any other name identifiers.
  • Keywords are fundamental part of Python language, its syntax and structure.
  • Keywords, similar to variable or function names, are case-sensitive.

Only three keywords have the first letter as CAPITAL (True, False, None), the rest is written in lower case (remember, keywords are case-sensitive)

All the keywords except True, False, and None are in lowercase and they must be written as it is. The list of all the keywords is given below.

Keywords in Python version 3.8.2


You can check the desired name against the list above easily to determine if it is a reserved keyword. This module allows a Python program to determine if a string or identifier is a keyword.

import keyword
  • Returns True if variable_name is reserved keyword
  • Returns False if variable_name is NOT reserved keyword
#if keyword

#if not keyword

Python Identifiers

An identifier is a name that the user gives to any user-created variables, functions, classes, decorators, generators etc.

Rule of thumb for identifiers nomenclature :

  • There is NO limit on the length of an identifier name. It can be a character or 1000.
  • Identifiers can be a combination of letters in lowercase (a to z) or uppercase (A to Z) or digits (0 to 9) or an underscore _.Names like MyFunc, myFunc, my_variable_1 and my_awesome_coding_skills, all are valid examples.
  • Identifiers can start with _, for example; __variable is viable but it cannot start with a number, for example; 22variable or 22_variable is not viable identifiers and Python throws a syntax error
  • Python reserved keywords cannot be used as identifiers.
class = 2020

File \"<interactive input>\", line 1
    class = 2020
SyntaxError: invalid syntax
  • We cannot use special symbols like !, @, #, $, % etc. in our identifier.
group@ = 3

File \"<interactive input>\", line 1
    group@ = 3
SyntaxError: invalid syntax
Previous Article