What are keywords ?
Keywords are an important concept of Python Language which is easy to understand and use. Keywords means that keywords are those words whose meaning and work is already reserved for Python Interpreter. We cannot make any changes in their working style. Just like the work of an aeroplane is to fly in the air. The work of an aeroplane is fixed, it has to fly, similarly the work of keywords is also fixed like: print() function is used to show the result on the screen. We can use print() function
You cannot make any changes to it, you can only use it. There are approximately 35+ keywords in the Python language. You can find out these keywords by running the code given below in Python.
import keyword
print(keyword.kwlist)
Using the above code, we can find out all the keywords available in Python language. Line by
line explanation of this code is given below.
1. import keyword : The keyword module file already available in Python language has been
imported.
2. print(keyword.kwlist) : This print() function displays the list of all the keywords
from the
keyword
file.
Types Of Keywords
Mainly Keywords in Python Language are divided into the following parts.
1. Importing : Importing Keywords are used in Python to import any module, file, library
etc. from, import, as etc. are examples of some importing Keywords.
2. Control Flow Keywords : Control Flow keywords are used to control the programs written
in Python language if, else, for, while etc. are Control Flow keywords.
3. Exception Handling Keywords : When we write programs, errors occur almost on running
the programs, hence to handle the errors Exception Handling keywords are used try, except,
finally etc. are Exception Handling Keywords.
4. Operators Keywords : Logical Operators Keywords are used to write logic in Python
Program and, or, not etc. are Logical operators keywords.
5. value keywords : True, False etc. value is keywords.
Key Rules of Python Keywords
1. Not Identifiers : Identifier names can never be placed on keyword names, like = >
if = "User" running like this gives an error.
2. Case sensitive : Keyword names are also case-sensitive, like print and PRINT are
both different keywords.
3. No Modifications : As already mentioned, the meaning of keywords is already reserved
in Python, which means we cannot make any changes in the function of keywords.
Advantages Of Keywords
1. Reserved Meaning : Since the meaning of keywords is already reserved, hence changes
cannot be made in the working of keywords.
2. Good performance : Since keywords have been created by the Python team, hence their
working is fixed and smooth.
3. Short Program : Since the work of keywords is already reserved, hence we can write
a short program using keywords without writing long code.