Keywords — The 35 Reserved Words
Keywords are the words Python owns. They define the language itself — you cannot use them as variable names, no matter how clever the idea seems.
See them all yourself
Python can list its keywords for you:
import keyword
print(keyword.kwlist)
print(len(keyword.kwlist))
Output (Python 3.12):
['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']
35
Thirty-five words. That’s the entire “vocabulary” Python reserves — English has hundreds of thousands. This smallness is a feature: you can learn every keyword in a week.
The proof they’re reserved
Try to use one as a variable:
for = 5
Output:
SyntaxError: invalid syntax
Python stops you instantly. Compare with a non-keyword:
for_you = 5 # fine — "for_you" is not the keyword "for"
The keywords, grouped by what they do
Values: True, False, None
Decisions: if, elif, else
Loops: for, while, break, continue
Functions: def, return, lambda, yield, pass, global, nonlocal
Classes & objects: class, self-adjacent tools like del
Logic: and, or, not, in, is
Errors: try, except, finally, raise, assert
Imports: import, from, as
Contexts: with, async, await
You already know some from Module 1. The rest arrive naturally, one per lesson — by the end of this course you’ll have used almost all 35 without ever sitting down to “memorize keywords.”
The three special-value keywords (meet them now)
True, False, and None appear constantly:
is_student = True
is_teacher = False
result = None # "nothing yet" — an empty placeholder
None deserves special attention: it means “no value here”, and it’s what functions return when they don’t return anything:
def say_hi():
print("hi")
x = say_hi()
print(x) # None — say_hi displays text but returns nothing
Common Errors & Fixes
SyntaxError: invalid syntaxon a line that looks fine — check if you used a keyword as a name (class = "10th",for = 5).NameError: name 'true' is not defined— Python keywords are case-sensitive: it’sTrue, nottrue. Same forFalseandNone. This one catches everyone coming from other languages.SyntaxError: cannot assign to True— trying to change a keyword’s value. They’re reserved; pick another name.
✅ Checkpoint
- How many keywords does Python have, and how could you list them yourself? (35 —
import keyword; print(keyword.kwlist)) - Which is valid:
import = 5orimporting = 5? (importing — “importing” is not the keyword “import”) - What does
Nonemean? (No value — an intentional empty placeholder) - Is it
trueorTrue? (True — keywords are case-sensitive)
Next: identifiers — the names you get to invent, and the rules that govern them.