Python Keywords and Identifiers

This lesson will teach you about identifiers (names given to variables, functions, etc.) and Python’s keywords and Terms, with examples to better understand the topics.

What are keywords in Python?

In Python, reserved words are referred to as keywords. The structure and syntax of the Python language are described using them. You can’t use a keyword to recognize anything, including variables, functions, or other types of code.

In Python, Keywords are case-sensitive. There are 33 keywords in Python; this figure can change slightly over time. Except for True, False, and None, all keywords are lowercase and must be written that way. Below is a list of all Python keywords.

List of all Python keywords.

TrueClassfinallyIs return


False, True

Python has two truth values: True and False. They are the outcomes of Python’s logical (Boolean) or comparison operations. For instance:

>> 100 == 100
>>> 98 > 3
>>> True or False
>>> 10 <= 8
>>> 379 > 700
>>> True and False

Since the first three statements in this example are true, the interpreter returns “True” while returning False for the other three statements. Python treats True and False as equivalent to 1 and 0. The following illustration can support this:

>> True == 1
>>> False == 0
>>> True + True

What is an Identifier in Python?

A name provided to an entity, such as a class, function, variable, etc., is called an identifier. Python identifies a variable, function, class, module, or other objects by a name or identifier.

The naming guidelines for Python identifiers

Python is a computer language that recognizes cases. The naming guidelines for Python identifiers are as follows:

  • An identifier begins with a letter, or an underscore (_), containing zero or more letters, digits, or both (0 to 9). Python forbids punctuation in identifiers, including @, $, and percent. Therefore, in Python, Staffing and staffing are two separate identifiers.
  • Examples of acceptable names include mySubject, var 1, and is_Valid_Name.
  • A digit cannot begin identification. Variable1 is an acceptable name; however, 1variable is not.
  • Keywords terms cannot be used as an identifier.

Example: global = 1

  • In Python programming, you cannot use special symbols like !, @, #, $, % as identifiers. Example: a@ = 0
  • Moreover, you can use an identifier of any length.
  • Uppercase letters are used to begin class names. The first letter of every other identifier is lowercase.
  • An identifier that begins with a single leading underscore is considered private.
  • A strongly private identity begins with two leading underscores.
  • If an identifier has two trailing underscores at the end, it is a language-defined special name.

Things to Keep in Mind

  1. A case-sensitive language is Python, implying that myname and MyName are distinct terms.
  2. Give the IDs sensible names at all times. While i = 10 is a valid name, count = 10 would make more sense and simplify understanding what it stands for when you next review your code.
  3. You can utilize an underscore to separate words, as this is a long variable. Example: Subject_Name_is_Math.

This concludes the Python Keywords and Identifiers lesson. In the next lesson, you will learn different comment types in Python and their usage.