Python Keywords Explained (Beginner Guide)

Python keywords are reserved words that have a special meaning in the language.

They matter because Python uses them to understand the structure of your code. If you use a keyword in the wrong place, you will usually get a syntax error. As a beginner, learning to recognize keywords will make Python code much easier to read.

You do not need to memorize every keyword right away. Start by understanding what keywords are, what they do, and how to avoid using them as names.

Quick way to check Python keywords

Python includes a built-in module named keyword that can show you the current keyword list and check whether a word is reserved.

import keyword

print(keyword.kwlist)
print(keyword.iskeyword("if"))
print(keyword.iskeyword("name"))

What this does:

  • keyword.kwlist shows all Python keywords
  • keyword.iskeyword("if") returns True
  • keyword.iskeyword("name") returns False

This is useful when you are not sure whether a word is allowed as a variable name.

What Python keywords are

Keywords are reserved words with special meaning in Python.

That means:

  • You cannot use them as variable names
  • You cannot use them as function names
  • You cannot use them as class names

Examples of Python keywords include:

  • if
  • else
  • for
  • while
  • def
  • class
  • return
  • import

For example, this code is invalid because for is a keyword:

for = 10

Python will raise an error because for already has a special meaning in the language.

Why keywords matter

Keywords are important because Python uses them to understand how your program is written.

For example:

  • if starts a condition
  • for starts a loop
  • def starts a function
  • return sends a value back from a function

If Python sees one of these words, it treats it as part of the language syntax, not as a normal name.

Using a keyword incorrectly often causes a syntax error, such as SyntaxError: invalid syntax.

Recognizing keywords also helps you read code faster. When you see if, for, or def, you can immediately tell what kind of code block you are looking at.

Common Python keywords beginners should know first

You do not need the full keyword list on day one. These are the most useful ones to learn first.

Condition keywords

  • if
  • elif
  • else

These are used to make decisions in code. If you are new to conditions, see Python if statements explained.

Loop keywords

  • for
  • while
  • break
  • continue
  • pass

These are used for repetition and loop control. To go deeper, read Python for loops explained.

Function keywords

  • def
  • return
  • lambda

These are related to functions. If you want the basics first, see Python functions explained.

Import keyword

  • import

This is used to bring code in from modules. For more on that, see how import works in Python.

Boolean and logic keywords

  • True
  • False
  • None
  • and
  • or
  • not

These are used in conditions and logical expressions.

Exception handling keywords

  • try
  • except
  • finally
  • raise

These are used when handling errors in your program.

How keywords are different from built-in functions

This is a very common beginner confusion.

Keywords

Keywords are part of Python syntax.

Examples:

  • if
  • for
  • def
  • return

You do not call a keyword like a function. For example, this is valid syntax:

if 5 > 3:
    print("Yes")

Here, if is a keyword. It does not use parentheses as a function call.

Built-in functions

Built-in functions are names you can call.

Examples:

  • print()
  • len()
  • type()

These use parentheses because you are calling them as functions:

print("Hello")
print(len("Python"))

So:

  • if is a keyword
  • print() is a function
  • len() is a function

If you want to learn more about these, see Python print() function explained and Python len() function explained.

Example: keywords used in real code

Here is a short program that uses several common keywords:

def get_message(number):
    if number > 0:
        return "Positive"
    else:
        return "Zero or negative"


for value in [3, 0, -2]:
    print(get_message(value))

Output:

Positive
Zero or negative
Zero or negative

Keywords used here

  • def — starts the function definition
  • if — checks a condition
  • return — sends a value back from the function
  • else — runs when the if condition is false
  • for — loops through the list
  • in — used as part of the for loop syntax

What the code does

  • It defines a function called get_message
  • The function checks whether a number is greater than zero
  • It returns a string based on the result
  • A for loop then calls the function for each number in a list

This is a good example of how keywords help form the structure of Python code.

If you want help understanding the bigger picture, Python syntax basics explained is a good next step.

How to see the full keyword list in Python

You can use the keyword module from Python’s standard library.

import keyword

print(keyword.kwlist)

This prints the full list of keywords for the version of Python you are using.

You can also check one word at a time:

import keyword

print(keyword.iskeyword("for"))
print(keyword.iskeyword("my_variable"))

Possible output:

True
False

This is useful because keyword lists can change slightly between Python versions.

If you want to run these checks quickly from the command line, you can use:

python -c "import keyword; print(keyword.kwlist)"
python -c "import keyword; print(keyword.iskeyword('for'))"
python -c "import keyword; print(keyword.iskeyword('my_variable'))"

Common beginner mistakes with keywords

Here are some of the most common problems beginners run into.

Trying to use a keyword as a variable name

This will fail:

class = "Beginner"

Use a different name instead:

class_name = "Beginner"

Confusing keywords with built-in functions

Many beginners think print and len are keywords.

They are not. They are built-in functions.

This matters because:

  • functions are called with parentheses
  • keywords are part of syntax

Forgetting that True, False, and None are special names

These are not ordinary variable names. They have special meaning in Python.

For example:

value = True
empty = None

These names are part of Python itself and should be used as intended.

Misspelling a keyword

Small spelling mistakes can break your code.

Example:

x = 10

elf x > 5:
    print("Big")

This is invalid because elf is not the keyword elif.

Misspelled keywords may cause:

  • a syntax error
  • a name error
  • confusing behavior if you do not notice the typo

Copying code without understanding reserved words

It is easy to copy code that uses words like try, return, or pass without knowing what they do.

A better approach is to pause and ask:

  • Is this word a keyword?
  • What role does it play in the code?
  • Is it starting a block, returning a value, or controlling flow?

What to learn next

Once you can recognize Python keywords, the next step is learning how they work together in real syntax.

Good next topics are:

The goal is not just to spot keywords, but to use them correctly in simple Python programs.

FAQ

What is a keyword in Python?

A keyword is a reserved word that Python uses as part of its syntax, such as if, for, and def.

Can I use a Python keyword as a variable name?

No. Keywords are reserved and will cause an error if you try to use them as names.

Is print a keyword in Python?

No. print() is a built-in function, not a keyword.

How do I see all Python keywords?

Use the keyword module and run print(keyword.kwlist).

Do Python keywords change?

Sometimes. The list can change slightly between Python versions.

See also