Skip to content

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.

Beginner 8 min read·Lesson 78 of 306 in Python Programming

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

Python
def future_feature():
pass
if condition:
pass
else:
act()
  • 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

Python
def send_report():
pass # will email the report later
send_report()
print("Program still runs")
Output
Program still runs

pass versus continue

Python
for n in range(3):
if n == 1:
pass
print("pass loop", n)
for n in range(3):
if n == 1:
continue
print("continue loop", n)
Output
pass loop 0
pass loop 1
pass loop 2
continue loop 0
continue loop 2

More examples

Planning a program with stubs

Python
def load_students():
return [("Asha", 82), ("Ben", 67)]
def save_report(report):
pass # writing to a file comes in Module 13
def build_report(students):
lines = []
for name, mark in students:
lines.append(f"{name}: {mark}")
return "\n".join(lines)
class ReportError(Exception):
pass
report = build_report(load_students())
save_report(report)
print(report)
print(issubclass(ReportError, Exception))
Output
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:

TextOutput
Asha: 82
Ben: 67
True

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

if bad:
pass
process(item) # still runs

Prefer

if bad:
continue
process(item)

pass does nothing; use continue to skip.

Silently swallowing errors

Avoid

try:
save()
except Exception:
pass

Prefer

try:
save()
except OSError as err:
print("Could not save:", err)

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

  1. 1
    Write the outline of a calculator program with stub functions add, subtract and menu using pass, and make it run.
  2. 2
    Explain 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?
Practise this topic