Keywords in Python | Python reserved words

Keywords in Python are pre-defined and reserved words. These words are defined by the Python creator. Every keyword has its own meaning and is defined to perform a particular task.

For example, the "if" keyword is used to allow the program to make a decision based on the given or certain conditions. Consider the following code as an illustration.

x = 10
y = 20

if x < y:
    print("The value of 'x' is less than the value of 'y'.")

The output should be:

The value of 'x' is less than the value of 'y'.

Because the value of "x" (10) is less than the value of "y" (20) in the above program, the condition "x < y" is true, and the "print()" statement or function was executed.

Keywords define the syntax and structure of the code and cannot be used as variable, function, or class names. A syntax error will result from doing so.

List of Python keywords (reserved words)

Here is the list of Python keywords (reserved words):

  1. and
  2. as
  3. assert
  4. break
  5. class
  6. continue
  7. def
  8. del
  9. elif
  10. else
  11. except
  12. False
  13. finally
  14. for
  15. from
  16. global
  17. if
  18. import
  19. in
  20. is
  21. lambda
  22. None
  23. nonlocal
  24. not
  25. or
  26. pass
  27. raise
  28. return
  29. True
  30. try
  31. while
  32. with
  33. yield

Note: Characters of all keywords are in lowercase except the three, which are: True, False, and None.

Can keywords be used as identifiers?

No, a keyword cannot be used as an identifier in Python.

What Is the Difference Between a Keyword and an Identifier?

Keywords are pre-defined by Python's creator, whereas identifiers are user-defined names given to variables, classes, functions, etc.

Advantages of the keywords in Python

Disadvantages of the keywords in Python

Python Online Test


« Previous Tutorial Next Tutorial »