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.
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:
- The language-defined special names start and end with two underscores each.
Eg: __init__ , __and__, __floordiv__.
- Multiple words can be separated using an underscore.
- Keywords cannot be used as identifiers.
- Class names always start with an uppercase letter, while the rest always starts with lowercase letters.
- 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.
>>> a@ = 0 File "<interactive input>", line 1 a@ = 0 ^ SyntaxError: invalid syntax
Above you can see after using special character as identifiers it shows an error.
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:
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