Skip to content
Home » Blog » Python Keywords and Identifiers

Python Keywords and Identifiers

Python Keywords and Identifiers

In this tutorial you’ll learn Python Keywords and Identifiers and how and where they can be used without triggering any errors, with all 33 Python keywords.

Python Identifiers

A python identifier is a name that you appoint to identify any sort of variables, functions, classes or any other objects.

An Identifier needs to start with a letter (A-Z/a-z) or an underscore(_). Use of special characters (@,#,$,% ..) in the name of an Identifier is prohibited.

Another thing to keep in mind remember is that Python is a case sensitive language. Hence, capitalization is a really import aspect of identifiers For example, Dog and dog are very different and has their own values.

There are a few conventions for Python identifiers:

  1. The language-defined special names start and end with two underscores each.
    Eg: __init__ , __and__, __floordiv__.
  2. Multiple words can be separated using an underscore.
    eg: long_word_used
  3. Keywords cannot be used as identifiers.
  4. Class names always start with an uppercase letter, while the rest always starts with lowercase letters.
  5. Identifiers cannot start with Digit/Numbers. 1identifer is invalid but Identifier1 will work.
>>> import = 1
 File "<interactive input>", line 1
   import = 1
          ^
SyntaxError: invalid syntax

Above we saw when we used the keyword as Identifiers it shows an error.

>>> [email protected] = 0
  File "<interactive input>", line 1
    [email protected] = 0
     ^
SyntaxError: invalid syntax

Above you can see after using special character as identifiers it shows an error.

Python Keywords

Some words are reserved by the python language to help define its syntax and structure, these reserved words are known as Keywords. These keywords cannot be used to name any identifiers.

Since Python is a case sensitive language, its keywords are also cased sensitive.

Every keyword is in lowercase except ‘True‘, ‘False‘ and ‘None‘.

There are 33 Keywords currently in Python 3.7, this numbers can vary as new versions of python are released.

Here is the list of all 33 Python Keywords as follows:

Falseclassfinallyis
returnNonecontinuefor
lambdatryTruedef
fromnonlocalwhileand
del globalnotwith
as elif ifor
yieldassertelseimport
passbreakexceptin
raise

Check out Python Programs to learn how you can use Python Keywords and Identifiers in a Program.

Ask your questions and clarify your doubts Python Keywords and Identifiers by commenting. Python Documentation

Leave a Reply

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.