Pass Statement

Python · Control Flow

Theory

pass is a statement that does nothing. It exists because Python's grammar requires every block, the body of an if, for, while, def, class or try, to contain at least one statement. A block holding only a comment is not enough, since comments are thrown away before compiling, so it raises IndentationError: expected an indented block. Writing pass satisfies the grammar while doing no work, and the program simply moves on, which is why the example prints done.

Typical uses are placeholders while you sketch the structure of a program (def load_data(): pass), empty classes such as custom exceptions (class InvalidOrder(Exception): pass), and deliberately ignoring a case. Do not confuse it with continue or break: pass has no effect on loops at all, continue jumps to the next iteration and break leaves the loop. An empty block that silently swallows errors, like except: pass, hides bugs, so use it with care.

Why we use it

While writing code top-down, you often know a function or branch is needed before you know what it should do. pass lets the program run and be tested now, with the empty pieces filled in later.

When to use it

Use pass as a temporary placeholder or for intentionally empty classes and blocks. Use continue to skip to the next loop iteration and break to exit a loop. A docstring or ... (Ellipsis) also works as a placeholder body in functions.

How it works

  1. Python reaches if status == 'pending':
  2. Is the condition true? Yes: Enter the block. No: Skip the block.
  3. Execute pass: nothing happens
  4. Leave the block normally
  5. Continue: print('done')

Syntax

if condition:
    pass

Example

status = "pending"
if status == "pending":
    pass  # TODO: handle later
print("done")

Key points

Python topics

Getting Started

Variables & Data Types

Operators

Strings

Lists

Tuples

Sets

Dictionaries

Control Flow

Loops

Functions & OOP

Working with Data

Tooling & Errors

File Handling

Exception Handling

NumPy Library

Pandas Basics

Data Cleaning

Combining DataFrames (SQL Joins & Unions)

GroupBy & SQL-Style Analytics

Reshaping & Workflow

Data Visualization

Machine Learning (Scikit-Learn)

Advanced Python & AI

T
Tech Town
Log InSign Up Free
Home SQL Python DSA Power BI Snowflake Databricks Spark Gen AI Practice Problems Contest Blog

Python for Data Analysts

From basics to business insights — the complete step-by-step Python roadmap. Click any topic in the sidebar to open it right here.

{{ sectionCount }}
Sections
{{ topicCount }}
Topics
Free
Forever
Hands-on practice Practice Python Online 141 Python questions for data analysts — strings, records, dates, statistics and regex — with hidden tests and instant verdicts. Start practising →
Section {{ sec.num }}

{{ sec.label }}

Python  /  {{ current.sectionLabel }}  /  {{ current.name }}

{{ current.name }}

Theory

{{ current.def }}

Why we use it

{{ rich.why }}

When to use it

{{ rich.when }}

Diagram

{{ rich.dg.caption }}

{{ tb.title }}
{{ c.v }}
{{ rich.dg.op }}
➜
{{ rich.dg.output.title }}
{{ c.v }}
{{ nd.label }}
{{ nd.sub }}
{{ nd.label }}
{{ nd.sub }}
{{ rich.dg.left.title }}
{{ it }}
{{ rich.dg.right.title }}
{{ it }}
Flowchart — how it works
{{ nd.text }}
{{ nd.text }}
◇ {{ nd.text }}
Yes → {{ nd.yes }}
No → {{ nd.no }}
Syntax
{{ current.syntax }}
Example
{{ current.example }}
▶ Try It Live — runs real Python 3.12 in your browser (first run loads the engine)
{{ liveOutput }}
{{ liveError }}
Key Points — click to check off as you learn
  • {{ pt.mark }} {{ pt.text }}

Share this topic