Reserved Words in Python

Unlike human languages, Python consists of a relatively small set of words. These words are called “reserved words”, and each of them has a specific meaning in the language.

However, when you write your own programs, you are free to create your own words as well. These are called variables, and you can choose their names freely—as long as they are not reserved words.

To understand this better, imagine dealing with a pet. You give it commands like “sit,” “stay,” or “fetch.” But if you use words it hasn’t been trained to understand, it will just stare at you in confusion.

Similarly, Python only understands its reserved words. For example, if you say something like:
“I wish more people walked to stay healthy,”
the only word Python might recognize is “walk”—because it is meaningful in its own language.

Here are some examples of Python reserved words:

and     del     global    not     with
as elif if or yield
assert else import pass
break except in raise
class finally is return
continue for lambda try
def from nonlocal while

Python already knows these words. For instance, when you use the word try, Python attempts to execute certain instructions. Don’t worry about the meanings of these words yet—you will learn them later. Let us analyze each of these keywords in detail. In order to make these keywords easy to understand, we have divided them into different catagories.

1. Logical & Boolean Operators

These control logical expressions.

  • and → True if both operands are true
  • or → True if at least one operand is true
  • not → Negates a condition
x = 5
print(x > 3 and x < 10) # True
print(not(x > 10)) # True

2. Conditional Statements

Used for decision-making.

  • if → Primary condition check
  • elif → Additional condition
  • else → Default block
if x > 10:
print("Big")
elif x > 5:
print("Medium")
else:
print("Small")

3. Looping & Iteration

Control repetitive execution.

  • for → Iterate over sequence
  • while → Loop while condition is true
  • break → Exit loop immediately
  • continue → Skip current iteration
  • pass → Placeholder (does nothing)
for i in range(3):
if i == 1:
continue
print(i)

4. Function & Scope Control

Define functions and manage variable scope.

  • def → Define a function
  • return → Exit function with value
  • lambda → Anonymous function
  • global → Use global variable
  • nonlocal → Use variable from enclosing scope
def add(a, b):
return a + bsquare = lambda x: x * x

5. Exception Handling

Manage runtime errors.

  • try → Block to test code
  • except → Handle exception
  • else → Runs if no exception
  • finally → Always executes
  • raise → Trigger exception
try:
x = int("abc")
except ValueError:
print("Error")
finally:
print("Done")

6. Object-Oriented Programming

Used in class definitions.

  • class → Define a class
class Car:
pass

7. Importing Modules

Bring external code into your program.

  • import → Import module
  • from → Import specific part
  • as → Alias
import math as m
from math import sqrt

8. Membership & Identity Operators

  • in → Check membership
  • is → Check identity (same object)
print(3 in [1,2,3])   # True

9. Context Management

  • with → Automatically manage resources (files, locks)
with open("file.txt") as f:
    data = f.read()

10. Generators & Iterators

  • yield → Produces values lazily (generator)
def count():
    yield 1
    yield 2

11. Assertions (Debugging)

  • assert → Checks condition, raises error if false
assert x > 0, "x must be positive"

12. Deletion

  • del → Delete variable/object
x = 10
del x

13. Miscellaneous / Flow Control

  • pass → No operation (placeholder)
  • break / continue → Already covered in loops

No Comments

Leave a Reply