Python pass Statement Explained

The Python pass statement is used when Python expects a block of code, but you do not want to add any real code yet.

Beginners often see pass in early practice programs, unfinished functions, or simple examples. It helps you write the structure of your program first without causing a syntax error.

Quick example

if True:
    pass

Use pass when Python requires an indented block but you do not want to run any code yet.

What the pass statement does

pass is a placeholder statement.

When Python runs it:

  • It does nothing
  • It produces no output
  • It does not change the program state

Its main purpose is to keep a block of code valid.

Python requires an indented block after lines that end with a colon, such as:

  • if
  • for
  • while
  • def
  • class
  • try
  • except

For example:

if 5 > 3:
    pass

print("Done")

Output

Done

The if block is valid because it contains pass, even though nothing happens inside it.

Why beginners need pass

Python does not allow empty code blocks.

If you write the start of a block and leave it empty, Python raises an error. This is one reason beginners often run into IndentationError: expected an indented block.

For example, this is invalid:

if True:

Python expects something indented under that if.

Using pass solves that problem:

if True:
    pass

This is useful when:

  • You want to sketch your program first
  • You are building a function step by step
  • You know a block will be filled in later
  • You want your code to run without finishing every part yet

Where pass is commonly used

Inside an if statement

When planning logic, you may want to create the condition first.

age = 15

if age >= 18:
    pass
else:
    print("Too young")

Output

Too young

If you are still learning conditionals, see Python if statements explained.

Inside a loop

pass can be used while testing loop structure.

for number in range(3):
    pass

print("Loop finished")

Output

Loop finished

This can be useful while learning Python for loops or Python while loops.

Inside a function

You can create a function now and finish it later.

def greet():
    pass

print("Function created")

Output

Function created

This is common when learning Python functions.

Inside a class

pass is often used in empty class definitions.

class Person:
    pass

user = Person()
print(type(user))

Output

<class '__main__.Person'>

This is a common pattern when starting with Python classes and objects.

Inside exception handling

During early debugging, you may temporarily leave an except block empty.

try:
    number = int("abc")
except ValueError:
    pass

print("Program continues")

Output

Program continues

Be careful with this pattern. Ignoring errors can make bugs harder to find.

pass vs comments vs ellipsis

These are not the same.

Comment

A comment is ignored by Python, but it does not count as a real statement by itself.

This still causes an error:

if True:
    # do this later

Python sees the block as empty.

pass

pass is a real Python statement, so it makes the block valid.

if True:
    # do this later
    pass

This works because pass is an actual statement.

Ellipsis (...)

You may sometimes see this:

def my_function():
    ...

This is valid Python, but pass is usually clearer for beginners. If your goal is an intentionally empty block, pass is the better choice.

When not to use pass

pass is helpful, but it should not be used carelessly.

Do not use it when:

  • You are hiding unfinished important logic for a long time
  • You actually need loop control like break or continue
  • The block should contain real behavior
  • You only forgot to finish your code

A common mistake is confusing pass with continue or break.

  • pass does nothing
  • continue skips to the next loop iteration
  • break stops the loop completely

Example:

for number in range(5):
    if number == 2:
        pass
    print(number)

Output

0
1
2
3
4

Even when number == 2, the loop continues normally because pass does not skip anything.

If you want to skip one iteration, use continue instead. See Python break and continue statements.

A missing block after one of these statements can cause an error:

  • if
  • for
  • while
  • def
  • class
  • try
  • except

This is especially common when:

  • Writing an if statement and leaving the body empty
  • Creating a function skeleton without adding code
  • Adding only comments inside a class or function
  • Confusing pass with continue or break
  • Forgetting that Python requires an indented block after a colon

For example, this causes an error:

def hello():
    # add greeting later

But this works:

def hello():
    # add greeting later
    pass

If you want to check your file for syntax and indentation problems, you can run:

python script.py
python -m py_compile script.py

If Python reports an indentation-related problem, read IndentationError: expected an indented block.

FAQ

Does pass do anything in Python?

No. It is a statement that does nothing, but it keeps the block syntactically valid.

Is pass the same as continue?

No. pass does nothing. continue skips to the next loop iteration.

Can I use a comment instead of pass?

No. A comment does not count as a statement, so the block is still considered empty.

Can pass be used in functions and classes?

Yes. It is often used in empty functions, classes, conditionals, and loops.

Should I leave pass in finished code?

Only if the empty block is intentional. Otherwise, replace it with real logic.

See also

If you keep learning Python block syntax, you will write cleaner code and avoid many common indentation errors.