Python Keywords and Glossary

Know Python's reserved and soft keywords, and use core programming vocabulary precisely.

Lesson 54 of 107Intermediate12 min read

Python keywords are the 35 reserved words that form the language's grammar, such as if, for, def, class, return and import. You can't use them as variable or function names. Python 3.10 and later also have a few soft keywords (match, case, _ and, from 3.12, type) that are special only in certain positions.

Python
import keyword
print(len(keyword.kwlist))        # 35 in Python 3.13
print(keyword.iskeyword("print")) # False: print is a built-in function

The second half of this lesson is a glossary: precise meanings for words used throughout the course and in Python documentation, such as parameter, argument, expression, iterable and mutable. Using them accurately makes documentation, error messages and interview questions much easier to follow. Examples come from a local history archive cataloguing boxes of documents.

Reserved keywords

The full list, grouped by purpose:

PurposeKeywords
ValuesTrue, False, None
Logic and testsand, or, not, in, is
Decisions and loopsif, elif, else, for, while, break, continue, pass
Functionsdef, return, lambda, yield
Classes and scopeclass, global, nonlocal, del
Errorstry, except, finally, raise, assert
Modulesimport, from, as
Context and asyncwith, async, await

import keyword; print(keyword.kwlist) prints the list for your Python version. Using a keyword as a name is a SyntaxError: class = "A" fails, which is why libraries write class_ or cls.

Built-in function names such as print, len, list, input and id are not keywords. Python lets you reassign them, but doing so hides the built-in, so treat them as reserved in practice.

Soft keywords

Soft keywords have a special meaning only in a particular context, and are ordinary names everywhere else. That allowed Python to add new syntax without breaking existing code that used those words as variable names.

Soft keywordSpecial inAdded
match, casematch statements3.10
_wildcard pattern in case _:3.10
typetype alias statements: type Point = tuple[float, float]3.12
Python
import re
match = re.search(r"\d+", "Box 14")   # still a normal variable name
print(match.group())                  # 14

keyword.softkwlist lists them, and the list differs between versions: type appears from 3.12. Code written for a newer Python may use them in ways an older interpreter can't parse.

Core vocabulary

These terms describe functions and code structure:

TermMeaningIn label_box(6)
parametera name in a function definitionnumber in def label_box(number):
argumentthe value passed when calling6
return valuewhat the function hands back"Archive box 6"
expressioncode that produces a valuef"Archive box {number}"
statementa complete instructionreturn ..., x = 5, if ...:
callrunning a function with ()label_box(6)
bindingassociating a name with an objectbox = label_box(6)

A printed message is output, not a return value: print() shows text and returns None. "Parameter" and "argument" are often used loosely in conversation, but error messages use them precisely, for example missing 1 required positional argument: 'number'.

Object vocabulary

These terms describe values and how they behave:

TermMeaningExamples
objectany value in Python; everything is one6, "box", a function
type / classwhat kind of object it isint, str, list
mutablecan change in placelist, dict, set
immutablecan't change; "changes" create new objectsint, str, tuple
hashableusable as a dict key or set memberstr, int, tuple of those
iterablecan be looped overlist, str, range, files
iteratorproduces items one by one with next()iter(list), generators
exceptionan object signalling an errorValueError("bad")

A name (variable) is a label bound to an object, not a box with a fixed type. box = 6 then box = "six" rebinds the same name to an object of a different type. Two names can refer to the same mutable object, which is why changes made through one are visible through the other.

Independent practice and a worked check

Task: explain binding, expression, statement, parameter, argument, iterable, mutation and exception with archive examples. Write each as a short comment beside a line of code that demonstrates it.

Python
boxes = ["letters", "maps"]               # binding: the name boxes refers to a list
total = len(boxes) + 1                    # expression: len(boxes) + 1 produces 3

def shelf_label(box_id):                  # parameter: box_id
    return f"Shelf {box_id}"              # statement: return

print(shelf_label(4))                     # argument: 4
for box in boxes:                         # iterable: the list supplies items
    print(box)
boxes.append("photos")                    # mutation: the same list grows
try:
    boxes.index("diaries")
except ValueError as error:               # exception: signals the failed search
    print("Not found:", error)

For the worked check: is print normally a reserved Python keyword? No. It's a built-in function, so keyword.iskeyword("print") returns False.

Reference and next practice

The language reference lists keywords and soft keywords, and the Python glossary defines hundreds of terms. Continue with the standard library essentials and the interview questions lesson. Practise with the Python exercises and Python quiz.

Python Keywords and Glossary Summary

  • Reserved keywords: Keywords such as if, class, return and import have defined grammatical roles.
  • Soft keywords: Some words have special meaning only in particular grammatical contexts.
  • Core vocabulary: An argument is a supplied value, a parameter is a declared input and a return value is a produced result.
  • Object vocabulary: Mutable objects can change state, iterables supply traversal and exceptions signal failures.

Python Keywords and Glossary Examples

Each example shows the code, the output it produces and what each part does.

Example 1

Python Keywords and Glossary in a small program

Python
import keyword
print(keyword.iskeyword("return"))
print(keyword.iskeyword("print"))
def label_box(number):
    return f"Archive box {number}"
print(label_box(6))
Output
True
False
Archive box 6
Line-by-line explanation
  1. Line 2return is a reserved keyword.
  2. Line 3print is a built-in function, not a keyword.
  3. Lines 4 to 5number is a parameter; the function returns a string.
  4. Line 66 is the argument; the return value is printed.
Example 2

Vocabulary in action

Python
import keyword

boxes = ["letters", "maps"]          # binding a name to a mutable list
catalogue = boxes                    # a second name for the same object
catalogue.append("photos")           # mutation is visible through both names
print(boxes)

def describe(item, prefix="Box"):    # item and prefix are parameters
    return f"{prefix}: {item}"       # an expression producing the return value

labels = [describe(b) for b in boxes]   # each b is an argument
print(labels[0])
print(hash("maps") == hash("maps"), isinstance(boxes, list))
print([w for w in ["match", "for", "type", "print"] if keyword.iskeyword(w)])
print([w for w in ["match", "for", "type", "print"] if keyword.issoftkeyword(w)])
Output
['letters', 'maps', 'photos']
Box: letters
True True
['for']
['match', 'type']
Line-by-line explanation
  1. Lines 3 to 5catalogue and boxes name the same list, so the append shows through both.
  2. Lines 8 to 9item and prefix are parameters; the f-string is the expression that gives the return value.
  3. Lines 14 to 15for is a reserved keyword; match and type are soft keywords, and print is neither.

Common Python Keywords and Glossary Mistakes

Using a keyword as a variable name

Don't
class = "Year 9"            # SyntaxError
from = "archive"            # SyntaxError
Do
class_name = "Year 9"
source = "archive"

Shadowing a built-in function

Don't
list = ["letters", "maps"]
boxes = list(range(3))      # TypeError: 'list' object is not callable
Do
box_list = ["letters", "maps"]
boxes = list(range(3))

Built-ins aren't keywords, so Python allows this; the original function is then hidden.

Python Keywords and Glossary in Real Projects

Why precise vocabulary matters

Documentation, error messages, code reviews and job interviews all use this vocabulary. An error such as TypeError: unhashable type: 'list' makes sense immediately once you know what hashable means, and a reviewer's comment "this function mutates its argument" points straight at the bug. Interview questions frequently probe the differences: mutable versus immutable, iterable versus iterator, is versus ==, parameter versus argument.

Editors and linters know the keyword list too: syntax highlighting colours keywords differently, and tools warn when you shadow a built-in. Python's own glossary is a good place to check a term you meet in documentation.

Python Keywords and Glossary FAQ

How many keywords are there in Python?

Python 3.13 has 35 reserved keywords, plus the soft keywords match, case, _ and type. The exact count changes occasionally between versions; len(keyword.kwlist) shows it for the interpreter you're running.

Is print a keyword in Python 3?

No. In Python 3, print is a built-in function. It was a statement keyword in Python 2, which is why old code writes print "Hello" without brackets.

What is the difference between a parameter and an argument?

A parameter is the name listed in a function definition, such as name in def greet(name):. An argument is the actual value passed in a call, such as "Ada" in greet("Ada").

Are True, False and None keywords?

Yes. They are reserved keywords with capital first letters, so you can't assign to them. true, false and none in lower case are ordinary names and cause NameError unless you define them.

What is a soft keyword in Python?

A word that acts as a keyword only in a specific context. match and case are keywords inside a match statement but can still be used as variable names elsewhere, which kept older code working when pattern matching was added in Python 3.10.

Python Keywords and Glossary Exercises

Answer each one and check it instantly. If you get stuck, open the hint before the answer.

Multiple choiceeasy

Is print normally a reserved Python keyword?

Multiple choicemedium

Which review concern is valid for Python keywords and glossary?

Python Keywords and Glossary Quiz

2 questions to check what you learned.

  1. Is print normally a reserved Python keyword?

    • Yes
    • No
    • Python ignores the distinction
  2. Which statement correctly describes core vocabulary?

    • An argument is a supplied value, a parameter is a declared input and a return value is a produced result.
    • Only the example output matters, not the rule
    • Every operation has the same behavior