This is an archived version of the course. Please find the latest version of the course on the main webpage.

Chapter 7: Naming variables

Keywords

face Josiah Wang

In the previous section, you have looked at variables, which is a type of identifier in Python.

There are some identifiers that are reserved in Python. They are called keywords or reserved words.

You cannot use these keywords as variable names. For example, you cannot use if as a variable name because Python needs it!

Type this to get a list of Python keywords.

>>> import keyword 
>>> keyword.kwlist
???

Here is the complete list for your convenience. There is no need to try to memorise them - Python will complain if you try to use them as variables.

You have seen a few of these already. You will be using more of them in future lessons!

  • False
  • True
  • None
  • and
  • as
  • assert
  • async
  • await
  • break
  • class
  • continue
  • def
  • del
  • elif
  • else
  • except
  • finally
  • for
  • from
  • global
  • if
  • import
  • in
  • is
  • lambda
  • nonlocal
  • not
  • or
  • pass
  • raise
  • return
  • try
  • while
  • with
  • yield