HOLIDAY SALE! Save 50% on Membership with code HOLIDAY50. Save 15% on Mentorship with code HOLIDAY15.

6) Variables and Types Lesson

Python Keywords

7 min to complete · By Martin Breuss

Python reserves a set of keywords that you can't use as variable names. Think of them as the vocabulary of the Python language. You can't assign your own meaning to these words because they already have a specific meaning.

If you go ahead and change their meaning, then you can't effectively talk with your computer anymore. Python reserved these words to be able to correctly interpret the meaning of your code, which is why they are called reserved keywords.

Below is a list of all these keywords as per Python 3.11. You will cover many of these keywords later on. For now, just skim over them, remember that they exist, and that you can't use them as variable names.

Python Reserved Word List

  • False
  • None
  • True
  • 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

This list is quite long! Of course, it's way too long for you to have fun remembering any of it when you're just getting started with programming.

Luckily, Python is constantly aware of all these keywords. It needs to be in order to correctly interpret your code! This means that you can always ask Python if you want to know what the reserved keywords are.

View the Python Reserved Words List

To bring up a list of all keywords in Python, you can ask Python for help() in regards to them:

help("keywords")

If you run this command in your Python interpreter, you'll get a full list of all Python keywords as your output:

Here is a list of the Python keywords. Enter any keyword to get more help.

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

These are the same keywords as the ones you saw further up. They're always available at your fingertips. You just need to ask Python for help() by running a single command.

As you can see, there's no need to remember this list. Instead, you can just remember how to find the list. In fact, that's a concept you'll encounter often when learning to program. You will externalize memorization to computers and get better at knowing how to access that knowledge.

Individual Keyword Documentation

From the helpful message at the top of the output from running help("keywords"), you may have gathered that you can also dive deeper into any of the individual keywords by passing one of their names into help():

help("False")

Running this command with any of the listed keywords will give you a lot of informative text output that you can read and study:

Help on bool object:

class bool(int)
 |  bool(x) -> bool
 |  
 |  Returns True when the argument x is true, False otherwise.
 |  The builtins True and False are the only two instances of the class bool.
 |  The class bool is a subclass of the class int and cannot be subclassed.
 ...

When you're done reading, you can quit this wordy and informative manual by pressing the q character on your keyboard.

Over time, some of these keywords will become quite familiar. A few might stay more obscure. Don't worry about it, and keep in mind that you can always check back on this list by asking Python for help() with a single line of code.

Additional Resources

If you want to dive really deep and learn more about Python keywords, read this excellent article called The 35 Words you need to Python.

Summary: Python Keywords

  • Python reserved words can't be used as variable names
  • You don't need to learn the keywords by heart
  • help("keywords") provides a list of all python reserved words
  • help() is used to get the documentation for a specific keyword