🚀 LEVEL UP TO SENIOR:Unlock 500+ Advanced Practical Challenges & Exercises.
🎓 COURSERA PARTNER:Earn professional Google, Meta, and IBM certificates to supercharge your resume.
REFERENCEpython

python Documentation

LOADING ENGINE...

pass Statement

AI & DATA SCIENCE // pass-statement

The pass statement does nothing at all — it's a placeholder used wherever Python's syntax requires a statement but you don't have any code to put there yet.

Syntax

def not_implemented_yet():
    pass

if condition:
    pass  # TODO

Deep Dive Course

Because Python uses indentation to define blocks, an empty block, like a function body, if branch, or loop body with nothing in it, is a syntax error — pass exists purely to satisfy that requirement without doing anything at runtime. It's commonly used for functions or classes stubbed out during early development, for branches that intentionally do nothing, or for explicitly catching and silently ignoring specific exceptions.

1Understanding pass Statement

Because Python uses indentation to define blocks, an empty block, like a function body, if branch, or loop body with nothing in it, is a syntax error — pass exists purely to satisfy that requirement without doing anything at runtime. It's commonly used for functions or classes stubbed out during early development, for branches that intentionally do nothing, or for explicitly catching and silently ignoring specific exceptions.

💡

pass is different from a docstring-only function body — a function containing only a string literal is valid without pass, since the string itself counts as a statement, but pass is still the clearest way to say 'deliberately empty' when there's no docstring.

editor.html
def upcoming_feature():
    pass

upcoming_feature()
print("Called without error")
localhost:3000

2Practical Example

Here is a real-world application of pass Statement showing how it is used in production Python code.

editor.html
for item in [1, 2, 3]:
    if item == 2:
        pass  # nothing special for this case yet
    else:
        print(item)
localhost:3000

3Best Practices

Follow these guidelines when working with pass Statement:

1. Use pass for stub functions/classes during early development instead of leaving a syntax error

2. Prefer pass over a meaningless placeholder statement when you need a genuinely empty block

3. Avoid pass in an except block unless silently ignoring that exception is truly the intended behavior — it's a common way to accidentally hide real bugs

⚠️

Tip: pass is different from a docstring-only function body — a function containing only a string literal is valid without pass, since the string itself counts as a statement, but pass is still the clearest way to say 'deliberately empty' when there's no docstring.

editor.html
def upcoming_feature():
    pass

upcoming_feature()
print("Called without error")
localhost:3000

Examples

Example 01Basic Usage
def upcoming_feature():
    pass

upcoming_feature()
print("Called without error")
Example 02Advanced Example
for item in [1, 2, 3]:
    if item == 2:
        pass  # nothing special for this case yet
    else:
        print(item)

Best Practices

  • Use pass for stub functions/classes during early development instead of leaving a syntax error
  • Prefer pass over a meaningless placeholder statement when you need a genuinely empty block
  • Avoid pass in an except block unless silently ignoring that exception is truly the intended behavior — it's a common way to accidentally hide real bugs

Interview Question

Why does Python need a pass statement at all, when brace-based languages allow genuinely empty blocks with just a pair of braces?

Hint: Think about how Python defines blocks compared to brace-based languages.

Languages that use braces can write an empty block as just an empty pair of braces, since the braces themselves delimit the block with no statement required inside. Python instead uses indentation to define blocks, and its grammar requires at least one statement following a colon — there's no equivalent of empty braces. pass exists specifically to be that placeholder statement, satisfying the grammar without having any effect at runtime.

Exercises

MediumPractice using pass Statement in a real scenario.
View Solution
def upcoming_feature():
    pass

upcoming_feature()
print("Called without error")

Frequently Asked Questions

Why does Python need a pass statement at all, when brace-based languages allow genuinely empty blocks with just a pair of braces?

Languages that use braces can write an empty block as just an empty pair of braces, since the braces themselves delimit the block with no statement required inside. Python instead uses indentation to define blocks, and its grammar requires at least one statement following a colon — there's no equivalent of empty braces. pass exists specifically to be that placeholder statement, satisfying the grammar without having any effect at runtime.

Related Functions

if-statementfor-loopdef-keyword