Skip to content
Tutorials Center
My learning

Topics

Python Reference ยท Statements and Keywords

The list of Python keywords

Complete list of Python keywords and soft keywords, what each one does, how to list them with the keyword module, and why you cannot use them as names.

Keywords are words with a fixed meaning in Python's grammar. You cannot use them as variable, function or class names, because the parser reserves them for statements, operators and literals. Python 3.14 has 35 reserved keywords; the standard keyword module reports the list for your running version.

A few more words, the soft keywords, are special only in certain positions and remain valid names elsewhere.

Try it

Python Ask Python for its keywords

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Python Keywords cannot be names

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Reserved keywords by purpose

Group Keywords
Constants True, False, None
Logic and tests and, or, not, in, is
Conditions if, elif, else
Loops for, while, break, continue
Functions def, return, lambda, yield
Classes class
Exceptions try, except, finally, raise, assert
Context with, as
Imports import, from
Scope global, nonlocal, del
Async async, await
Placeholder pass

That is 35 words in total. keyword.kwlist prints them sorted, with False, None and True first.

Soft keywords

Word Where it is special
match, case In match statements (3.10+).
_ As the wildcard pattern inside case.
type At the start of a type X = ... statement (3.12+).

Soft keywords are fine as variable names in ordinary code, though reusing type shadows the built-in function.

Usage notes

  • Built-ins are not keywords. print, len, list, str, id and input are ordinary names that you can rebind, usually by mistake. Avoid it.
  • Case matters. True, False and None are capitalized; true and none are plain identifiers.
  • Attribute access. A keyword cannot appear as an attribute name in source (obj.class is a syntax error); use getattr(obj, "class") or rename.
  • Keyword arguments can not be keywords either: write from_= or class_= and use a trailing underscore, as PEP 8 recommends.
  • The list grows. async and await became real keywords in 3.7. Old code using them as names breaks on new versions.
  • Removed: print and exec were statements in Python 2 and are normal functions now.
  • Check programmatically with keyword.iskeyword(name) when generating code or accepting identifiers from users.