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.

Answer from sebastian_oe on Stack Overflow
🌐
W3Schools
w3schools.com › python › ref_keyword_pass.asp
Python pass Keyword
When the pass statement is executed, nothing happens, but you avoid getting an error when empty code is not allowed. Empty code is not allowed in loops, function definitions, class definitions, or in if statements.
🌐
W3Schools
w3schools.com › python › python_if_pass.asp
Python Pass Statement
In empty functions or classes that you plan to implement later · During development, you might want to sketch out your program structure before implementing the details. The pass statement allows you to do this without syntax errors. ... age = 16 if age < 18: pass # TODO: Add underage logic later else: print("Access granted") Try it Yourself » · A comment is ignored by Python, but pass is an actual statement that gets executed (though it does nothing).
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-pass-statement
Python pass Statement - GeeksforGeeks
The pass keyword in a function is used when we define a function but don't want to implement its logic immediately. It allows the function to be syntactically valid, even though it doesn’t perform any actions yet.
Published   October 4, 2025
🌐
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
522

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
264

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”)

🌐
W3Schools
w3schools.com › python › gloss_python_function_pass.asp
Python Function Pass
Python Examples Python Compiler Python Exercises Python Quiz Python Challenges Python Server Python Syllabus Python Study Plan Python Interview Q&A Python Bootcamp Python Certificate Python Training ... function definitions cannot be empty, but if you for some reason have a function definition with no content, put in the pass statement to avoid getting an error.
🌐
Real Python
realpython.com › python-pass
The pass Statement: How to Do Nothing in Python – Real Python
September 25, 2023 - 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 ...
🌐
Programiz
programiz.com › python-programming › pass-statement
Python pass Statement (With Examples)
In Python programming, the pass statement is a null statement which can be used as a placeholder for future code.
Find elsewhere
🌐
LearnDataSci
learndatasci.com › solutions › python-pass
Python pass statement: When, why, and how to use it – LearnDataSci
This article looks specifically at the pass statement. As mentioned previously, pass is usually used as a placeholder for branches, functions, classes. Whenever Python arrives at a pass statement, it passes straight over it (hence the name).
🌐
Python
docs.python.org › 2.0 › ref › pass.html
6.4 The pass statement
It is useful as a placeholder when a statement is required syntactically, but no code needs to be executed, for example: def f(arg): pass # a function that does nothing (yet) class C: pass # a class with no methods (yet)
🌐
Educative
educative.io › answers › what-is-pass-statement-in-python
What is pass statement in Python?
That's it! Running the code above above gives no error. In this case, pass tells Python to skip that block, making the syntax valid. Go ahead and remove even a single pass statement in the code above, it would give an IndentationError.
🌐
W3Schools
w3schools.com › python › gloss_python_if_pass.asp
Python The pass Keyword in If
Python Examples Python Compiler Python Exercises Python Quiz Python Challenges Python Server Python Syllabus Python Study Plan Python Interview Q&A Python Bootcamp Python Certificate Python Training ... if statements cannot be empty, but if you for some reason have an if statement with no content, put in the pass statement to avoid getting an error.
🌐
W3Schools
w3schools.com › python › gloss_python_for_pass.asp
Python The pass Keyword in For Loops
Python Examples Python Compiler Python Exercises Python Quiz Python Challenges Python Server Python Syllabus Python Study Plan Python Interview Q&A Python Bootcamp Python Certificate Python Training ... for loops cannot be empty, but if you for some reason have a for loop with no content, put in the pass statement to avoid getting an error.
🌐
W3Schools
w3schools.com › python › gloss_python_class_pass.asp
Python The pass Keyword in Class
Python Examples Python Compiler Python Exercises Python Quiz Python Challenges Python Server Python Syllabus Python Study Plan Python Interview Q&A Python Bootcamp Python Certificate Python Training ... class definitions cannot be empty, but if you for some reason have a class definition with no content, put in the pass statement to avoid getting an error.
🌐
STechies
stechies.com › python-pass-statement
How to Use the Pass Statement in Python?
Pass statement is used when we want to declare an empty function or conditions or loops like if, for, while, etc. Let’s understand it more with the help of a few examples. ... # Python program to explain pass statement string1 = "Stechies" ...
🌐
Wiingy
wiingy.com › home › learn › python › pass statement in python
Pass Statement in Python (With Examples)
January 30, 2025 - The pass statement is used in Python programming to create an empty or insufficient code block. The pass statement has no effect on the Python interpreter; it simply causes it to move on to the next statement.
🌐
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....
🌐
W3Schools Blog
w3schools.blog › home › python pass
Python pass - W3schools
September 7, 2018 - Python Pass statement is used to pass by without the execution of current iteration in between the loop. for x in "ALPHA_NUMERIC. CHARACTERS":
🌐
iO Flood
ioflood.com › blog › python-pass
Python 'pass' Statement | Guide (With Examples)
June 7, 2024 - Inside the loop, we’ve set a condition: if ‘i’ equals 3, then pass. The ‘pass’ statement here means that Python should do nothing. It should simply continue with the next iteration.
🌐
Datamentor
datamentor.io › python › pass-statement
Python pass Statement (With Examples)
By using the pass statement as the class body, it serves as a placeholder to satisfy the syntax requirement of defining a class. It allows the class to be defined without specifying any specific attributes or methods at that moment. ... In this code, the if statement checks if the condition ...