Coding For Kids & Teens

Python Keywords and Reserved Words Explained for Kids

Python has 35 words it will not let your child use as a name. Those 35 are not the problem. They announce themselves loudly, on the right line, the moment the file runs. The words that genuinely confuse children learning Python are the ones Python does allow, accepts without comment, and then punishes three lines later with a message that mentions neither the name nor the mistake.

This matters most in the first few months after a child leaves block-based coding. In Scratch you choose a variable from a menu, so naming collisions cannot happen. In Python your child types whatever they like, and the language trusts them. Understanding Python keywords and reserved words is really about understanding which of those two failures you are looking at, because one takes ten seconds to fix and the other can end a project.

What this post covers

  • The 35 reserved keywords, and why Python refuses to run at all when one is used as a name.
  • The riskier group: built-in names like list, print and sum, which Python permits and then breaks.
  • Why the error message names a type rather than the name your child chose.
  • The four soft keywords that are only reserved some of the time.
  • A one-line check your child can run, and the naming habit that makes it unnecessary.

What is a keyword in Python?

A keyword is a word the language has kept for its own grammar. The Python language reference puts it precisely: these "names are used as reserved words, or keywords of the language, and cannot be used as ordinary identifiers. They must be spelled exactly as written here."

There are 35 of them:

FalseNoneTrueandas
assertasyncawaitbreakclass
continuedefdelelifelse
exceptfinallyforfromglobal
ifimportinislambda
nonlocalnotorpassraise
returntrywhilewithyield

Nobody needs to memorise that grid, and asking a ten-year-old to is a waste of a lesson. Most of these words a child will meet naturally in the first year of Python, and the handful they will never touch, such as nonlocal and await, are not words anybody reaches for as a variable name anyway. The useful fact is that the list is short, fixed and checkable.

What happens if your child uses one as a name?

Python stops. It does not run one line and then fall over. Given a file whose first line is class = 5, Python reports:

File "<string>", line 1
    class = 5
          ^
SyntaxError: invalid syntax

Read what that message gives you. The line number is 1. The offending line is reprinted. A small arrow sits directly under the character that broke it. Nothing ran, so there is no partly-finished output to interpret.

This is the good failure, and it is worth telling your child so. A keyword collision is caught before the program starts, points at itself, and is fixed by renaming one variable. Children who have learned to read the error message rather than panic at it handle this in seconds. The post linked there covers how to read the message; this one is about why the message sometimes points somewhere useless.

The names that cause real trouble are not keywords

Here is the fact that reframes the whole topic. Ask Python whether list is a keyword and it says no:

>>> import keyword
>>> keyword.iskeyword('class')
True
>>> keyword.iskeyword('list')
False

list is a built-in function name, not a reserved word. So Python lets your child use it, says nothing, and carries on. Watch what that produces:

list = [1, 2, 3]
print(len(list))        # prints 3, everything looks fine
list(range(3))          # TypeError: 'list' object is not callable

The first two lines work. The variable is created, the length prints correctly, and a child reasonably concludes the name was fine. The program only breaks when something tries to use list as a function again, which might be twenty lines later, or inside a piece of code the child copied from a tutorial and never looked at.

The same thing happens with the names children reach for most:

What the child wroteWhat breaksWhat Python says
print = 'hello'The next print(...)TypeError: 'str' object is not callable
sum = 10The next sum([...])TypeError: 'int' object is not callable
list = [1, 2, 3]The next list(...)TypeError: 'list' object is not callable

In every case the error is reported on the second line, the one that used the function, not the first line where the damage was done. The child stares at a line that is completely correct.

Not sure which level your child should start at? A free trial class with a Codeyoung teacher shows you exactly where they are and what they are ready for next, before you commit to anything.

Book a Free Trial →

Why is the error message so unhelpful here?

Because it describes what Python found, not what your child intended. Look again at TypeError: 'int' object is not callable. It names the type that ended up in the way, which is an integer. It does not name sum. It does not use the word "variable". It gives no hint that the real event happened earlier and was a naming decision.

For an adult developer that message is enough, because they already know what shadowing is and the word "callable" is familiar. For a child it is a dead end. They have been taught that the error tells you where the problem is, and here the error is telling the truth about the wrong line.

So the teaching point is narrow and genuinely useful: when the broken line looks fine, suspect a name. That single heuristic turns an unfixable error into a search. Ask your child to scroll up and look for the function's name on the left of an equals sign. They will find it, and the moment they find it once they rarely make the mistake again. It is the same instinct behind treating debugging as a taught skill rather than a personality trait.

Soft keywords: reserved only sometimes

There is a middle category, and it exists because Python's designers did not want to break old code. Four names are soft keywords, reserved only in specific contexts: match, case, type, and a single underscore when used as a wildcard inside a case pattern.

The language reference explains that these "syntactically act as keywords in their specific contexts, but this distinction is done at the parser level, not when tokenizing." In plain terms, inside a match statement they behave like keywords, and everywhere else they are ordinary names. So this runs perfectly well:

match = 5
print(match)            # prints 5

match and case arrived as soft keywords in Python 3.10, and type joined them in 3.12. The practical upshot for a learner is modest but worth saying once: a tutorial or a list of keywords written before 2021 is incomplete, and a child who finds two different keyword counts online is not confused, they are reading two different Python versions.

Infographic contrasting a keyword error that lands on the line the child typed with a built-in name error that lands four lines later, a grid of Python's 35 reserved keywords with its four soft keywords shown separately, and three examples showing class equals five stopping at once while print and sum break later
Keywords fail on the line you typed. Built-in names fail somewhere else.

How to teach this at home, without a lecture

Five minutes, once, at the right moment. The right moment is the first time your child hits one of these errors, not before.

  1. Show them the check. Open Python, type import keyword, then keyword.iskeyword('list'). Let them try their own variable names. Children enjoy this because it answers instantly and they are in charge of it.
  2. Explain its limit honestly. True means stop. False does not mean yes. That gap is the whole lesson, and children handle the nuance better than most adults expect.
  3. Teach one naming habit instead of a list. Add a word. Not list but score_list. Not sum but total_sum. Not print but print_name. A specific name is both safer and easier to read in a month's time.
  4. Give them the heuristic. If the line in the error message looks correct, look upwards for a name.
  5. Let them break it on purpose. Have them write the three-line sum = 10 example themselves and read the error. A failure they caused deliberately is not frightening, and they will recognise it when it happens by accident.

Deliberately breaking something is a better teaching move here than any explanation, because the gap between cause and symptom is the thing being taught, and you cannot describe that gap as vividly as a child can experience it in thirty seconds.

When is a child ready for this?

It depends much less on age than on what they are building, and rushing it does real harm. My own view, after years of watching children make the jump from blocks to text, is that naming problems should be taught when they appear rather than taught in advance.

StageTypical ageWhat to do about names
Block coding, Scratch7 to 10Nothing. Blocks make collisions impossible, so there is nothing to warn about
First weeks of Python10 to 12Teach the naming habit only. Add a word to every variable name
Writing programs over 20 lines11 to 13Teach the keyword check and the SyntaxError. This is when collisions start
Using libraries and copied code12 and upTeach shadowing properly, with the sum and list examples

A child who is genuinely ready to leave Scratch can absorb all of this in one session. A child pushed into text syntax early will meet the shadowing error before they have the mental model to interpret it, decide Python is arbitrary and unfair, and quietly lose interest. That is the outcome worth avoiding, and it is why we hold children in blocks until the logic is secure rather than until a birthday.

If your child is still assembling the vocabulary, our guide to 40 common programming terms and the comparison of Scratch and Python are the right place to start instead. You can also check the current list yourself any time in the Python keyword module documentation.

What to take away

Python's 35 reserved keywords are the easy case: they stop the program on the line that caused the problem and the arrow points at it. The hard case is the built-in names, which are not reserved, which Python accepts in silence, and which produce a TypeError on a line that is not at fault. Teach the habit of adding a word to every name and most of this disappears before it starts.

And if your child is staring at an error on a line that looks perfectly fine, they have probably met this exact problem. Scroll up, look for the name, rename it, move on.

Codeyoung runs 1:1 live online classes for children aged 6 to 17, with a teacher who adapts the pace to your child rather than a fixed syllabus. The first class is free, so you can see how they respond before deciding.

Book a Free Trial

Our online coding classes for kids move children from blocks to Python at the pace the child sets, which is the only way this particular lesson lands when it should.

Frequently Asked Questions

What are keywords in Python?
Keywords are the 35 names Python has reserved for itself, such as if, for, class and return. The language documentation says they cannot be used as ordinary identifiers and must be spelled exactly as written, so a child cannot name a variable after one of them.
How many keywords does Python have?
Thirty-five, plus four soft keywords that are only reserved in particular situations. Your child can check the count on any computer by opening Python and running import keyword then len(keyword.kwlist), which is a more reliable answer than a list copied from a website.
What happens if you use a Python keyword as a variable name?
Python refuses to run the file at all and reports a SyntaxError on that exact line, with a small arrow pointing at the problem. Nothing executes, so there is no half-finished program to untangle. It is the easiest kind of error to fix.
Why does naming a variable list or print cause a strange error later?
Because those are built-in function names, not keywords, so Python allows the name and quietly replaces the function. The program keeps running until something tries to use the original function, and the error then appears on that later line instead.
Are match and case Python keywords?
They are soft keywords, which means they only act as keywords inside a match statement. Outside one, match = 5 is perfectly legal Python. The other two soft keywords are type and the single underscore used as a wildcard in a case pattern.
How can my child check whether a name is safe to use?
Run import keyword then keyword.iskeyword with the name in quotes. True means pick something else. False does not mean the name is wise, because built-in names return False, so the better habit is naming things specifically, like score_list rather than list.

Turn your child’s curiosity into creativity 🚀

Book a free 1:1 trial class and see how Codeyoung makes learning fun and effective.

Arpita Jain

Arpita Jain
I head curriculum design for Codeyoung's coding program. For the last 10+ years, I've built K-12 computer science curricula, and today I oversee the Scratch-through-Python pathway that thousands of Codeyoung kids learn on. The question I care about most is the one every parent eventually asks: what should my kid actually be learning at each age, and in what order? Too much kids' coding rushes children into typing real code before they're ready — and they bounce off it. I built our age-banded curriculum to do the opposite: logic and confidence first, with visual block coding, then real syntax once a child is genuinely ready for it.

Codeyoung Perspectives

Codeyoung Perspectives is a thought space where educators, parents, and innovators explore ideas shaping how children learn in the digital age. From coding and creativity to strong foundational math, critical thinking and future skills, we share insights, stories, and expert opinions to inspire better learning experiences for every child.