In Python, some keywords (like if, for, while, def, class) must be followed by an indented block of code. If you leave it empty, Python throws an error.
That’s where pass comes in. It’s a placeholder that tells Python:
“I haven’t written anything here yet, but this block is valid.”
It literally does nothing — but it keeps your code running.
if True:
pass
Without the pass, that snippet would cause a syntax error.
Why use pass?
a) Sketching out code (stubs)
When you’re planning your program, you can write the structure without filling in details.
def load_data():
pass # to be implemented later
This way, you can run the file without errors while you gradually build things.
b) Empty classes
Sometimes you want a class that doesn’t do anything yet, but you still need the definition:
class User:
pass
c) Do-nothing branches
You may want to acknowledge a condition but intentionally skip it.
for item in items:
if not item.valid:
pass # ignore invalid items
else:
print(item)
How it behaves
- Functions: A function with only
passreturnsNone. - Loops: The loop still runs, but each cycle does nothing.
- Exceptions:
except: passis valid but dangerous — it hides errors silently. Use it only if you really want to ignore something.
try:
risky_code()
except ValueError:
pass # not recommended unless ignoring is intentional
pass vs other options
pass: Do nothing, but keep block valid.raise NotImplementedError(): Better if a function must be filled in later (so you don’t forget)....(ellipsis): Another placeholder, often used in type hints or class stubs, but less common thanpass.
Think of pass as “legal emptiness”, while NotImplementedError is “you shouldn’t call this yet.”
Try it yourself
- Write a function
def greet():that usespass. Call it — what does it return? - Write a
forloop that runs 5 times with onlypassinside. Add aprint()later and see the difference. - Create a
try/exceptthat catches an error. First usepass, then replace it withprint("Error caught!"). Notice the debugging difference.
Quick tips
- Use
passto keep code valid while planning. - Avoid
except: passunless you’re absolutely sure you don’t care about the error. - Add comments like
# TODOnearpassso you remember to come back.
👉 That’s it! pass is one of the simplest Python keywords, but it’s surprisingly handy when you’re building code step by step.





