Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content
No results
  • About AskPython
  • Blog
  • Contact Me
  • Free Online Developer Tools Hub
  • Home
  • Meet the Team
  • Privacy Policy
  • Python
  • Python Course for Beginners Online FREE
  • Python Tutorial – Mega Index
  • Terms and Conditions

🚀 Supercharge your YouTube channel's growth with AI.

Try YTGrowAI Free
  • Home
  • Blog
  • About AskPython
  • Python Course
  • Start Here

Python pass Statement – pass Keyword in Python

  • Pankaj KumarPankaj Kumar
  • October 5, 2026
  • Python Programming
Python pass Statement - pass Keyword in Python

An empty function body is invalid in Python, even when the function should do nothing for now. The pass statement gives the function body a statement without performing an operation.

I’ll show how pass keeps an empty function valid and explain why a comment alone cannot replace it.

TL;DR: Python pass does nothing

The pass statement performs no operation, but it gives a Python code block the statement its syntax requires. Use it when a valid function, class, or branch should intentionally have no behavior yet.

  • pass does not skip a loop iteration. Use continue for that.
  • A comment alone does not make an otherwise empty code block valid.
  • A function containing only pass returns None when called.

What is the pass statement in Python?

pass is a null operation, which means Python executes the statement and makes no change. A code block, also called a suite, is the indented body after a statement such as if or def. Python requires that body to contain a statement.

That makes pass useful for a deliberate empty branch or a temporary function or class definition. A comment can explain what is planned, but it is not a Python statement and cannot fill that required place.

The distinction is between syntax and behavior. pass makes a definition valid now, while the function or class still needs an implementation before it can perform a task.

The Python language reference calls pass a null operation and explains its use when syntax requires a statement but no code should run in its pass statement entry.

How to use pass in Python code blocks

Use pass on its own line at the indentation level where Python expects the block’s statement. These examples show a conditional branch, a function, and a class.

Step 1: Leave a conditional branch empty

This branch takes no action when the value is even. The other branch appends odd values to a new list.

def remove_evens(numbers):
    odds = []
    for number in numbers:
        if number % 2 == 0:
            pass
        else:
            odds.append(number)
    return odds

print(remove_evens([1, 2, 3, 4, 5, 6]))

Output

[1, 3, 5]

The loop continues after pass. The even number is ignored because the branch has no operation, not because pass changes the loop.

Step 2: Define a function without a body of work

A function definition still needs a statement in its body. Calling this function runs pass and returns None, Python’s default return value when a function reaches its end without returning a value.

def pending():
    pass

print(pending())

Output

None

pass makes the definition syntactically complete. It does not cause the function to return a useful result.

Step 3: Create an empty class

A class can also have a pass statement as its entire body when the class currently has no attributes or methods.

class Pending:
    pass

print(Pending.__name__)

Output

Pending

The class is defined with its name and can be used like other class objects. pass adds no methods or fields.

Terminal output showing Python pass in an if branch, empty function, and empty class

Common errors with the Python pass statement

pass is not a substitute for every kind of “do nothing.” Pick a statement that matches the behavior you want.

SituationUseEffect
Keep a required block emptypassRuns no operation, then execution continues normally
Skip the rest of this loop iterationcontinueMoves to the next iteration of the innermost loop
Explain unfinished workComment or TODODocuments intent but does not make an empty block valid

For example, this function body is still empty because Python ignores comments when it parses a suite:

def pending():
    # TODO: implement this later

Running that exact definition with Python 3.11.16 produces this error because the comment is ignored and the function body has no statement.

IndentationError: expected an indented block after function definition on line 1

Add pass on its own indented line if the function must remain runnable before its implementation is ready. For loop control, see the Python tutorial’s section on break and continue.

Conclusion: Keep pass for code that must do nothing

Use pass when Python requires a statement but that block should do nothing. If the goal is to skip a loop iteration, continue expresses that behavior instead.

For related reading, see Python functions and Python indentation.

Frequently asked questions

These quick answers distinguish pass from the statements and placeholders it is often confused with.

What does pass do in Python?

pass is a null operation. It satisfies a code block that requires a statement while performing no operation.

Does pass skip a loop iteration?

No. pass does nothing and the loop proceeds to the next statement. Use continue to skip the rest of the current iteration.

Can a comment replace pass in an empty function?

No. Python ignores comments when parsing a code block, so a comment alone does not satisfy the required statement. Use pass for a valid empty function body.

Pankaj Kumar
Pankaj Kumar

I have been working on Python programming for more than 12 years. At AskPython, I share my learning on Python with other fellow developers.

Articles: 264
Python Namespace and Variable Scope Resolution (LEGB)
Previous Post Python Namespace and Variable Scope Resolution (LEGB)
Next Post Python break Statement
Python break Statement

Related Posts

What Does %s Mean in Python String Formatting?

What Does %s Mean in a Python Format String?

  • November 30, 2026
Python Convert String to List

Python Convert String to List: Choose the Right Method

  • November 29, 2026
Translate String Python

Translate String Python

  • November 29, 2026

Partner Websites

  • GoLangDocs
  • LinuxForDevices
  • CodeForGeek

Popular Categories

  • Python Programming
  • Python Modules
  • OOPS in Python
  • Python Programming Examples
  • Strings in Python

Hall of Fame

  • Python Programming
  • OOPS in Python
  • Creating Python Modules
  • Args and Kwargs in Python
  • Python Dictionary (Dict) Tutorial
  • Python List – 15 Things You MUST Know
  • Python Set – Things You MUST Know
  • Python String Functions: Methods by Task

Important Links

  • Home
  • Python Course
  • Start Here
  • Blog
  • About AskPython
Latest posts
  • np.linalg.eig: Eigenvalues and Eigenvectors
  • What Does %s Mean in a Python Format String?
  • How to Use np.sin() in NumPy
  • cv2.imread: Load Images with OpenCV
  • pd.read_json: Read JSON Into a DataFrame

Copyright © 2026 - AskPython. All rights reserved.