Python’s Pass Placeholder

Landscape illustration showing Python code with class, def, and if blocks, each using pass as placeholder.

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.

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.

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:

c) Do-nothing branches

You may want to acknowledge a condition but intentionally skip it.

How it behaves

  • Functions: A function with only pass returns None.
  • Loops: The loop still runs, but each cycle does nothing.
  • Exceptions: except: pass is valid but dangerous — it hides errors silently. Use it only if you really want to ignore something.

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 than pass.

Think of pass as “legal emptiness”, while NotImplementedError is “you shouldn’t call this yet.”

Try it yourself

  1. Write a function def greet(): that uses pass. Call it — what does it return?
  2. Write a for loop that runs 5 times with only pass inside. Add a print() later and see the difference.
  3. Create a try/except that catches an error. First use pass, then replace it with print("Error caught!"). Notice the debugging difference.

Quick tips

  • Use pass to keep code valid while planning.
  • Avoid except: pass unless you’re absolutely sure you don’t care about the error.
  • Add comments like # TODO near pass so 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.

Main Topic

Python Program Flow

A colourful cartoon-style landscape illustration shows a playful flowchart. On one side, a path forks into two labelled branches representing an if…else decision, while nearby a looping curved arrow shows repetition for a loop. The scene is bright and engaging, making programming concepts feel approachable and fun.

Learn how Python uses if…else decisions and loops to guide program flow, choices, and repetition.

Other Tutorials in this Topic

A colourful cartoon-style landscape illustration shows two runners on a track. One runner stops early at a finish line with a sign labelled “break”, while another leaps over hurdles marked “continue”, symbolising Python loop controls. The background is bright and playful, making programming concepts easy to visualise.

Python Breaking from Loops

Beginner’s guide to Python loop controls: learn break and continue for smarter, more flexible repetition.

ChatGPT said: A colourful cartoon-style landscape illustration shows a student sitting at a school desk, glancing at their watch with a sigh. The classroom clock on the wall shows school hours, and the student looks impatient, waiting to go home but unable to leave while class is still in session.

Python While Loops

Beginner’s guide to Python while loops: repeat actions until conditions change, with clear examples and practice tasks.

A colourful cartoon-style landscape illustration shows a cheerful monkey standing by a moving conveyor belt, happily taking pieces of fruit off as they pass. The background is bright and playful, symbolising repetition and order, like a Python for loop.

Python For Loops

Beginner’s guide to Python for loops: repeat actions, process lists, and simplify tasks with clear examples.

A colourful cartoon-style landscape illustration shows a cheerful character standing at a wooden signpost. The path splits into two clear directions, with one arrow marked if and the other marked else, symbolising decision-making in Python programming.

Python If/Else Decsion Making

Beginner’s guide to Python if…else statements: learn how programs make choices and follow different paths with examples.