🌐
Python
docs.python.org › 2.0 › ref › pass.html
6.4 The pass statement
pass is a null operation -- when it is executed, nothing happens.
🌐
Codecademy
codecademy.com › docs › python › keywords › pass
Python | Keywords | pass | Codecademy
October 22, 2025 - The pass keyword in Python acts as a placeholder in code blocks (like functions or loops) where no action is required.
🌐
Real Python
realpython.com › python-pass
The pass Statement: How to Do Nothing in Python – Real Python
March 18, 2026 - In this tutorial, you'll learn about the Python pass statement, which tells the interpreter to do nothing. Even though pass has no effect on program execution, it can be useful. You'll see several use cases for pass as well as some alternative ...
🌐
W3Schools
w3schools.com › python › ref_keyword_pass.asp
Python pass Keyword
Python Examples Python Compiler ... Study Plan Python Interview Q&A Python Training ... The pass statement is used as a placeholder for future code....
🌐
Note.nkmk.me
note.nkmk.me › home › python
The pass Statement in Python | note.nkmk.me
May 9, 2023 - pass is a null operation — when it is executed, nothing happens. It is useful as a placeholder when a statement is required syntactically, but no code needs to be executed 7. Simple statements - The pass statement — Python 3.11.3 documentation
🌐
Readthedocs
pypass.readthedocs.io › en › latest › introduction.html
python-pass — pypass documentation
Python-pass is tested for python ... gpg --import-ownertrust pypass/tests/test_ownertrust.txt ... Documentation for python-pass is available on pypass.rtfd.org....
🌐
Hackr
hackr.io › home › articles › programming › python
Pass Python | Docs With Examples
February 13, 2025 - pass is a syntactic placeholder; the interpreter executes it without errors. Python comments (#) are ignored by the interpreter and do not affect execution.
🌐
Programiz
programiz.com › python-programming › pass-statement
Python pass Statement (With Examples)
In Python, pass is a null statement and it does nothing when executed. Despite not doing anything, pass does have a purpose...In such cases, we can use the pass statement as a placeholder. For example,
🌐
Real Python
realpython.com › ref › keywords › pass
pass | Python Keywords – Real Python
A placeholder statement that allows you to write syntactically correct code without executing any operations.
Find elsewhere
🌐
DataCamp
datacamp.com › tutorial › python-pass
How to Use the Python pass Statement | DataCamp
July 11, 2024 - For example, you can place the ... empty. ... The Python pass statement serves as a placeholder in situations where a statement is syntactically necessary, but no actual code is needed....
🌐
Unstop
unstop.com › home › blog › python pass statement | uses, alternatives & more (+examples)
Python Pass Statement | Uses, Alternatives & More (+Examples)
October 21, 2024 - The pass statement in Python is a placeholder that does nothing when executed. It's used when a statement is syntactically required, but no action is needed.
🌐
IONOS
ionos.com › digital guide › websites › web development › python pass
How to use Python pass - IONOS
August 1, 2023 - Python pass uses the pass command and is placed within the code block. Python pass is used primarily in loops, where a certain function may not have been defined yet. The place­hold­er is often used after an “if” statement.
🌐
GeeksforGeeks
geeksforgeeks.org › python-pass-statement
Python pass Statement - GeeksforGeeks
Pass statement in Python is a null operation or a placeholder. It is used when a statement is syntactically required but we don't want to execute any code.
Published: January 4, 2025
🌐
iO Flood
ioflood.com › blog › python-pass
Python 'pass' Statement | Guide (With Examples)
June 7, 2024 - In this example, we’ve defined a function named ‘my_function’. Inside the function, we’ve placed the ‘pass’ statement as a placeholder. When we call ‘my_function()’, Python executes the ‘pass’ statement, which does nothing, and then moves on.
🌐
Tutorialspoint
tutorialspoint.com › python › python_pass_statement.htm
Python - pass Statement
Python pass statement is used when a statement is required syntactically but you do not want any command or code to execute. It is a null which means nothing happens when it executes.
Top answer
1 of 16
523

Suppose you are designing a new class with some methods that you don't want to implement, yet.

class MyClass(object):
    def meth_a(self):
        pass

    def meth_b(self):
        print "I'm meth_b"

If you were to leave out the pass, the code wouldn't run.

You would then get an:

IndentationError: expected an indented block

To summarize, the pass statement does nothing particular, but it can act as a placeholder, as demonstrated here.

2 of 16
263

Python has the syntactical requirement that code blocks (after if, except, def, class etc.) cannot be empty. Empty code blocks are however useful in a variety of different contexts, such as in examples below, which are the most frequent use cases I have seen.

Therefore, if nothing is supposed to happen in a code block, a pass is needed for such a block to not produce an IndentationError. Alternatively, any statement (including just a term to be evaluated, like the Ellipsis literal ... or a string, most often a docstring) can be used, but the pass makes clear that indeed nothing is supposed to happen, and does not need to be actually evaluated and (at least temporarily) stored in memory.

  • Ignoring (all or) a certain type of Exception (example from xml):

     try:
         self.version = "Expat %d.%d.%d" % expat.version_info
     except AttributeError:
         pass # unknown
    

    Note: Ignoring all types of raises, as in the following example from pandas, is generally considered bad practice, because it also catches exceptions that should probably be passed on to the caller, e.g. KeyboardInterrupt or SystemExit (or even HardwareIsOnFireError – How do you know you aren't running on a custom box with specific errors defined, which some calling application would want to know about?).

     try:
         os.unlink(filename_larry)
     except:
         pass
    

    Instead using at least except Error: or in this case preferably except OSError: is considered much better practice. A quick analysis of all Python modules I have installed gave me that more than 10% of all except ...: pass statements catch all exceptions, so it's still a frequent pattern in Python programming.

  • Deriving an exception class that does not add new behaviour (e.g., in SciPy):

     class CompileError(Exception):
         pass
    

    Similarly, classes intended as abstract base class often have an explicit empty __init__ or other methods that subclasses are supposed to derive (e.g., pebl):

     class _BaseSubmittingController(_BaseController):
         def submit(self, tasks): pass
         def retrieve(self, deferred_results): pass
    
  • Testing that code runs properly for a few test values, without caring about the results (from mpmath):

     for x, error in MDNewton(mp, f, (1,-2), verbose=0,
                              norm=lambda x: norm(x, inf)):
         pass
    
  • In class or function definitions, often a docstring is already in place as the obligatory statement to be executed as the only thing in the block. In such cases, the block may contain pass in addition to the docstring in order to say “This is indeed intended to do nothing.”, for example in pebl:

     class ParsingError(Exception):
         """Error encountered while parsing an ill-formed datafile."""
         pass
    
  • In some cases, pass is used as a placeholder to say “This method/class/if-block/... has not been implemented yet, but this will be the place to do it”, although I personally prefer the Ellipsis literal ... in order to strictly differentiate between this and the intentional “no-op” in the previous example. (Note that the Ellipsis literal is a valid expression only in Python 3)

    For example, if I write a model in broad strokes, I might write

     def update_agent(agent):
         ...
    

    where others might have

     def update_agent(agent):
         pass
    

    before

     def time_step(agents):
         for agent in agents:
             update_agent(agent)
    

    as a reminder to fill in the update_agent function at a later point, but run some tests already to see if the rest of the code behaves as intended. (A third option for this case is raise NotImplementedError. This is useful in particular for two cases: Either “This abstract method should be implemented by every subclass, and there isn't a generic way to define it in this base class”, or “This function, with this name, is not yet implemented in this release, but this is what its signature will look like”)

🌐
Simplilearn
simplilearn.com › home › resources › software development › what is pass in python and usage of pass function in python
What Is Pass in Python and Usage of Pass Function in Python
October 4, 2022 - Pass in python is a null statement used as a placeholder for future code. Read this tutorial to learn all about pass function and it's usage in python!
Address: 5851 Legacy Circle, 6th Floor, Plano, TX 75024 United States
🌐
CodingNomads
codingnomads.com › python-pass-keyword
Python Pass Keyword
Python doesn't do anything when it encounters the pass keyword, but execution can continue.
🌐
Built In
builtin.com › software-engineering-perspectives › pass-vs-continue-python
Pass vs. Continue in Python Explained | Built In
In Python (and other programming languages), loops help to iterate over a list, tuple, string, dictionary and a set. Pass: The pass statement in Python is used when a statement or a condition is required to be present in the program, but we don’t ...