English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Python Basic Tutorial

Python Flow Control

Python Functions

Python Data Types

Python File Operations

Python Objects and Classes

Python Date and Time

Advanced Python Knowledge

Python Reference Manual

Python Keywords and Identifiers

In this tutorial, you will learn about keywords (reserved words in Python) and identifiers (names of variables, functions, etc.).

Python keywords

keywords are reserved words in Python.

we cannot use keywords as  variable name,functionnames or any other identifiers. They are used to define the syntax and structure of the Python language.

Keywords in Python are case-sensitive.

Python 3.7contains 33 number of keywords. This number may change slightly over time.

All keywords must be lowercase, except True, False, and None. The following lists all keywords.

keywords in Python
Falseawaitelseimportpass
Nonebreakexceptinraise
Trueclassfinallyisreturn
andcontinueforlambdatry
asdeffromnonlocalwhile
assertdelglobalnotwith
asyncelififoryield

it may be difficult to view all keywords at once and try to understand their meanings.

If you want to view the list of all keywords, here isall keywordscompletelistand examples.

Python identifiers

Identifiers are names given to entities such as classes, functions, and variables. They help distinguish one entity from another.

rules for writing identifiers

  1. Identifiers can be lowercase letters(a to z)or uppercase letters(A to Z)or a number(0 to 9)or the combination of underscores (_). myClass, var_1, var_name_1, print_this_to_screen are all valid.

  2. Identifiers cannot start with a number.1variable is invalid, but variable1 is valid.

  3. keywords cannot be used as identifiers.

    >>> global = 1
      File "<interactive input>", line 1
        global = 1
               ^
    SyntaxError: invalid syntax
  4. We cannot use keywords like.,@,#,$,such as special symbols.

    >>> a@ = 0
      File "<interactive input>", line 1
        a@ = 0
         ^
    SyntaxError: invalid syntax
  5. Identifiers can be of any length.

things to remember

Python is Case sensitive language. This means Variable and variable are two different variables. Also, it is recommended that meaningful identifiers be used at all times in actual programming.

Although, c = 10 is also valid. However, using count = 10 It will look more meaningful, and it will be easier to understand its function and meaning even if you look at the code after a long period of time.

You can use underscores to separate multiple words for naming, for example: this_is_a_long_variable