Python pass Statement
Table of Contents + −
In the last lesson you learned the continue Statement. It skips the rest of the current loop turn and jumps to the next one. So continue does something. Now we look at the opposite idea. It is a keyword that does nothing at all. That sounds useless, right? But you will reach for it more often than you think.
🤔 Why do we need a “do nothing” keyword?
Here is the pain. In Python, the way you group code is by indentation. So whenever you write a line that ends in a colon, Python expects an indented block right below it.
That rule applies to a lot of things:
- An
if, anelif, anelse. - A
forloop or awhileloop. - A
def(a function) or aclass. - A
try/except.
Every one of those needs at least one real line of code under it. So if you leave that block empty, Python does not run your program. It stops with an error before anything happens.
Now think about a normal moment while coding. You are sketching out your program. You know you need an if here. But you have not decided what goes inside it yet. You just want to mark the spot and keep moving.
So you write the if and leave it blank.
This if has no body. Python refuses to accept it:
age = 20
if age >= 18: # I'll write this part laterprint("Done")Output
IndentationError: expected an indented block after 'if' statement on line 3See the problem? A comment is not real code. Python ignores comments completely. So as far as Python is concerned, that block is still empty. And an empty block is a SyntaxError.
That is the exact gap pass fills. It is the official “do nothing here, but keep this valid” placeholder.
🧩 What pass actually does
The pass statement is a real statement that performs no action. It just sits there. When Python reaches it, it does nothing and moves to the next line.
Think of it like an empty parking spot with a “reserved” sign. The spot exists. It holds the space. But no car is in it yet. pass holds the space in your code the same way.
Here is the same example, now fixed with pass:
age = 20
if age >= 18: pass # I'll write this part later
print("Done")Output
DoneNo error this time. Python sees pass. It treats it as a complete (but empty) block. Then it keeps going. The print runs and you see Done.
So the rule is simple. The block needed one statement. pass is that one statement. It just happens to do nothing.
🛠️ Where you will actually use it
A stub is an empty version of something you plan to finish later. You write the outside shape now and fill the inside in later. pass is how you make that empty shape legal. Let us walk through the real spots where this comes up.
Stub out a function you will fill in later
This is the most common use. You know the function’s name and its inputs. You just have not written the logic yet.
def send_email(address): pass # TODO: connect to the email service later
send_email("alex@example.com")print("Program still runs")Output
Program still runsThe function exists. You can call it. And nothing breaks. So you can write the rest of your program around it, then come back and fill in the email logic when you are ready.
Stub out a class
Same idea, but for a class. Sometimes you just need the name to exist for now.
class Order: pass
my_order = Order()print(type(my_order))Output
<class '__main__.Order'>The class works. You can make objects from it. You will add the real fields and methods later.
A branch of an if you will handle later
Maybe you have decided you need an else, but you have not figured out what it should do. So you mark it and move on.
score = 90
if score >= 50: print("You passed")else: pass # TODO: send a "try again" message laterOutput
You passedAn except that swallows an error on purpose
Sometimes you really do want to catch an error and then ignore it. So the except block has nothing in it. pass makes that legal.
data = {"name": "Riya"}
try: print(data["age"])except KeyError: pass # the key is missing, and that's fine here
print("We kept going")Output
We kept goingSo here pass says “yes, an error happened, and I am choosing to do nothing about it.”
Caution
An empty except is powerful, so use it carefully. Swallowing every error can hide real bugs. Catch the specific error you expect (like KeyError above), not a bare except: that hides everything.
An empty loop body
Now and then you want a loop that runs but does not do anything inside it yet. pass keeps the body valid while you design it.
for item in [1, 2, 3]: pass # TODO: process each item later
print("Loop finished")Output
Loop finished🆚 pass vs continue vs break vs return vs …
This is where people get confused. A bunch of things look like they “do nothing” or “skip something”, but they are not the same. So let us line them up side by side.
| Keyword | What it does | Where you use it |
|---|---|---|
pass | Nothing at all. Execution just moves to the next line. It is only a placeholder so an empty block is legal. | Any empty block: if, loop, function, class, except. |
continue | Skips the rest of this loop turn and jumps to the next turn. | Inside a loop only. |
break | Stops the loop completely and leaves it right away. | Inside a loop only. |
return | Leaves the whole function and hands back a value. | Inside a function only. |
... (Ellipsis) | Also a valid empty placeholder, often used to mean “to be done”. It is an object, not a true do-nothing keyword. | Stubs, type hints, some libraries. |
Here is the big thing to hold onto. pass does literally nothing and execution just moves on to whatever line comes next. It does not skip a turn. It does not stop a loop. It does not leave a function. The others all change the flow of your program. pass does not.
You might also see ... (three dots, called the Ellipsis) used the same way as a stub. Both work to fill an empty block. pass is the clearer, more common choice for beginners, so prefer it.
Tip
If you are inside a loop and you want to skip the rest of this turn, you want continue, not pass. pass would just do nothing and the lines below it would still run.
⚠️ Common Mistakes
A few traps catch people with pass. Watch out for these.
Using a comment instead of pass. A comment alone does not satisfy Python. So you still get an error. Remember, Python ignores comments, so the block is still empty.
# ❌ Avoid: comment-only block still errorsdef save(): # do later
# ✅ Good: pass makes it a valid empty blockdef save(): passExpecting pass to skip a loop turn. It does not. It just does nothing, and the loop body keeps running below it. This is the one that bites people the most.
for n in range(3): # ❌ Avoid: this does NOT skip; print still runs if n == 1: pass print(n)That prints 0, 1, and 2. The pass changed nothing. If you actually wanted to skip printing 1, you needed continue there, not pass.
Leaving pass in forever. It is meant to be temporary. It is a marker you come back and replace. If a real pass stays in your code for weeks, you probably forgot to finish that part.
✅ Best Practices
Keep these habits and pass stays helpful.
- Treat
passas a temporary marker. The plan is to replace it with real code soon, not to keep it around. - Pair
passwith a# TODOcomment so future-you knows what still needs writing. A line likepass # TODO: validate the inputis a great habit. - Use it for honest placeholders, like a stub function or class you will fill in soon.
- Once you add the real code, delete the
pass. It is no longer doing a job. - Reach for
passonly when the block is truly empty. If you meant to skip a loop turn, usecontinueinstead.
🧩 What You’ve Learned
✅ Python needs an indented block after any line ending in a colon, and an empty block is a syntax error.
✅ pass is a do-nothing placeholder that makes an empty block legal so your code runs.
✅ It is useful for stub functions, empty classes, an except you ignore on purpose, and branches you have not written yet.
✅ A comment cannot replace pass, because Python ignores comments.
✅ pass does nothing, while continue skips a loop turn, break stops a loop, and return leaves a function.
✅ Pair pass with a # TODO comment and replace it once you write the real code.
Check Your Knowledge
Test what you learned. Pick an answer for each question, then click Check.
- 1
Why does Python need the pass statement?
Why: Python requires at least one statement in a block, and pass provides one that does nothing.
- 2
What does pass actually do when it runs?
Why: pass performs no action; it only exists so the block is not empty, and execution continues with the next line.
- 3
Can a comment be used instead of pass to fill an empty block?
Why: Comments are invisible to Python, so they cannot satisfy the requirement for a non-empty block.
- 4
Inside a loop, you want to skip the rest of the current turn. Which keyword do you use?
Why: continue jumps to the next iteration, while pass does nothing and lets the lines below it still run.
🚀 What’s Next?
Now that you can hold a spot with pass, it is time to put loops inside other loops and handle grids of data.