Module 6 · Loops and Iteration — topic 9 of 12
pass
pass is a statement that does nothing. Learn why Python needs it, where it is used (empty blocks, stubs during development, minimal classes and ignored exceptions) and how it differs from continue.
Learning objectives
- Explain why Python needs pass
- Use pass to keep empty blocks valid
- Distinguish pass from continue and break
Definition
pass is a statement that does nothing. Learn why Python needs it, where it is used (empty blocks, stubs during development, minimal classes and ignored exceptions) and how it differs from continue.
Introduction
pass is Python’s “do nothing” statement. Because Python uses indentation instead of braces, every block must contain at least one statement. When you need a block that intentionally has no action, pass fills it.
Why it matters
While designing a program you often write the outline first: functions and branches whose details will come later. pass keeps that outline runnable so you can test the parts already written.
Detailed explanation
pass can appear anywhere a statement is allowed: in if, elif and else blocks, loop bodies, function bodies and class bodies.
It has no effect at all; execution simply moves on to the next statement.
In a loop, pass does not skip anything. Code after pass in the same block still runs. That is the key difference from continue, which jumps to the next iteration, and break, which leaves the loop.
Typical uses: a stub function you will fill in later, an empty class used as a simple marker, or an except block where ignoring an error is genuinely correct (with a comment explaining why).
The literal ... (Ellipsis) is sometimes used for stubs in the same way, but pass is clearer for beginners.
Leaving pass in finished code where real handling is needed hides problems; search for it before you call a program done.
Syntax
- pass fills a block that would otherwise be empty.
- It performs no action.
- The program continues normally after it.
Code examples
A stub that keeps the program running
Program still runs
pass versus continue
pass loop 0 pass loop 1 pass loop 2 continue loop 0 continue loop 2
More examples
Planning a program with stubs
Asha: 82 Ben: 67 True
Step-by-step explanation
- save_report is a stub: the program’s structure is complete, but saving isn’t implemented yet.
- build_report is fully written and can be tested now.
- ReportError is a minimal custom exception class whose body is just pass.
- The program runs end to end, so each piece can be developed and checked separately.
Expected output
Running “Planning a program with stubs” prints exactly:
Practical applications
- Developers sketch a module’s functions with pass before implementing them.
- Custom exception classes are often defined with only pass in the body.
- Interface or base classes sometimes contain methods that do nothing by default.
Best practices
- Use pass for intentional empty blocks and stubs.
- Add a comment explaining why a block is empty.
- Search for leftover pass statements before finishing a feature.
Common mistakes
Expecting pass to skip the rest of the loop
Avoid
Prefer
pass does nothing; use continue to skip.
Silently swallowing errors
Avoid
Prefer
Ignoring all errors hides real problems; handle specific errors or report them.
Key takeaways
- pass is a statement that does nothing.
- It keeps empty blocks syntactically valid.
- Unlike continue or break, it doesn’t change the loop’s flow.
Try it yourself
- 1Write the outline of a calculator program with stub functions add, subtract and menu using pass, and make it run.
- 2Explain in one sentence each what pass, continue and break do inside a loop.
Finished reading? Mark it complete to update your dashboard.
Suggested practice
1 question test this exact topic. Answers and explanations are revealed after you submit.
- BeginnerWhat does the pass statement do?