Skip to content
BENIBIX Learn

Keyword

Development🧩 Programming ConceptsPrograms

Also known as Reserved Word

A word the language keeps for itself, like if or return. You cannot reuse it.

Think of it like

Think of it like the words on road signs. Stop and Go mean one thing only, so nobody may use them as a name.

Example

Emma tries to name a variable class in Python. Python stops her, because class is a keyword.

Why it matters

Keywords are the skeleton of every program. Knowing the short list makes any code easier to read.

Definition

A keyword is a word that a programming language keeps for itself. Words like if, for, while and return already have a fixed meaning. You cannot use them as names for your own things. Most code editors show keywords in their own colour. Each language has its own short list of them.

Example code

python
>>> import keyword
>>> keyword.iskeyword("while")
True
>>> keyword.iskeyword("apple")
False
Python can tell you itself which words it keeps for its own use.

Common mistake

Using a keyword as a name, then getting an error that seems to make no sense.

Key takeaways

  1. 1
    Fixed meaning. Each keyword does one job in the language.
  2. 2
    Not for names. You cannot call your own things by them.
  3. 3
    Short list. Most languages have only a few dozen.

Learn it properly