LambdaLabTM
Computer Science · Class 11 · Empty Statements
Types of StatementsEmpty⏱️ 10 min read

The pass Statement

pass is the whole of the empty statement: one word, no brackets, no value, nothing after it. Running it does nothing. The interesting question is not what it does — you already know — but why anyone would write it on purpose. This lesson is the answer.

1How it is written

shape.py
pass

That is the entire syntax. It is a keyword, like if and for, so you cannot use the word pass as a variable name. It takes no condition and no value, and it is a single-word statement — it fills a line on its own.

Watch Out
It does not mean “pass” as in an exam. A student who sees pass under if marks >= 33: and reads it as “print Pass” has it exactly backwards: that block prints nothing at all. The word means pass over it — skip past, do nothing.

2Use 1: the skeleton, before the logic exists

This is what pass is really for. When you plan a program, the shape arrives before the details — you know there will be three branches long before you know what any of them says. pass lets you write the shape down and still run the file.

Step through the four drafts. Each one fills in a branch, and each one runs:

⭕ Four drafts of one program

Write one branch at a time. pass keeps the rest legal until you get there.

3 pass left
grades.py
headerbody — the indented blockoutside
marks = 78
if marks >= 90:
pass
elif marks >= 60:
pass
else:
pass
what this draft prints
marks = 95
(nothing)
marks = 78as shown
(nothing)
marks = 41
(nothing)

The shape of the whole program, and not one line of the work. It is a legal program — it runs, and it prints nothing whatever the marks are. Three pass statements are all that is holding the three blocks open.

Notice what draft 1 did: it printed nothing, for every mark. That is not a broken program — it is an unfinished one that works exactly as much as it has been written. You could hand it to a friend and it would not crash.

Tip
Get in the habit of writing the headers first with pass underneath each one, then running the file before you fill anything in. Any spelling mistake, missing colon or wrong indentation shows up immediately, while the program is still four lines long and easy to read.

3The same trick inside a loop

A loop body can be left for later in exactly the same way. Here is a factorial program that has been planned but not written:

factorial_plan.py
# the plan: multiply f by every number from 1 to num
num = 5
f = 1

for i in range(1, num + 1):
    pass  # the multiplying goes here

print(f)
Output
1

It runs, the loop goes round five times doing nothing, and f is still 1 at the end — the answer is wrong, but the program is alive and you can see it working. Now the body gets written and the pass goes:

factorial.py
# same program, with the body filled in
num = 5
f = 1

for i in range(1, num + 1):
    f = f * i

print(f)
Output
120
Note
pass is not part of the finished program. It held the block open until there was something to put in it, and then it was replaced. Finding a pass in code you are reading usually means somebody has not written this bit yet.

4Use 2: a branch that is meant to do nothing

Sometimes the empty block is the finished answer. A temperature logger might want to shout about extreme readings and stay completely silent about normal ones:

temperature.py
# only the extremes are worth mentioning
reading = 25

if reading > 40:
    print('Too hot!')
elif reading < 5:
    print('Too cold!')
else:
    pass

print('Reading recorded:', reading)
Output
Reading recorded: 25
Watch Out
Be honest about this one. That else and its pass could both be deleted — the two lines together do nothing, and the program behaves identically without them. Some programmers keep it to say “I thought about this case and there is nothing to do”, which is a real message to the next reader. Others call it clutter. Both are defensible; what is not defensible is writing it because you think Python needs it. Here it does not.

Where pass is genuinely needed is when the block would otherwise be the only thing in the statement — the skeletons above. If deleting the whole header along with it leaves the program you meant, you did not need either.

5pass vs a comment vs nothing

In the blockIs it a statement?The program
nothingnoIndentationError — nothing runs
# a commentnoIndentationError — nothing runs
passyesruns, and the block does nothing
pass # noteyesruns — the comment is just a note

The last row is the one to copy. Write pass so the program runs, and put the note beside it so you remember what belongs there.

6Try it

Below is a skeleton that runs and does nothing. Replace each pass with a print(), one at a time, running it after every change — that is how the drafts above were made.

ticket.py

7You will meet it again

Note
Later chapters add more headers that end in a colon and demand a block of their own — functions and classes. The rule does not change there, and neither does the repair: a block with nothing in it yet gets a pass. That is where you will see it most often in real code.

8Recap

Key Takeaway
pass is a keyword, a single-word statement, and the only empty statement Python has. It does nothing when it runs. Its job is to be a statement, so a block that has no work in it yet is still legal — which lets you write and run the shape of a program before you have written the program.
Quick Check

An if block contains one line, and that line is pass. The condition is True. What is printed?

Quick Check

Which is the best reason to write pass?

Quick Check

A loop body contains only pass. How many times does the body run?