🌐
W3Schools
w3schools.com › python › ref_keyword_pass.asp
Python pass Keyword
Python Training ... The pass statement is used as a placeholder for future code. When the pass statement is executed, nothing happens, but you avoid getting an error when empty code is not allowed.
🌐
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).
🌐
W3Schools
w3schools.com › python › gloss_python_function_pass.asp
Python Function Pass
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. ... Python Functions Tutorial Function Call a Function Function Arguments *args Keyword Arguments **kwargs Default Parameter Value Passing a List as an Argument Function Return Value Function Recursion ... If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail: sales@w3schools.com
🌐
W3Schools
w3schools.com › python › gloss_python_class_pass.asp
Python The pass Keyword in Class
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. ... Python Syntax Tutorial Class Create Class The Class __init__() Function Object Methods self Modify Object Properties Delete Object Properties Delete Object ... If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail: sales@w3schools.com
🌐
W3Schools
w3schools.com › python › gloss_python_for_pass.asp
Python The pass Keyword in For Loops
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. ... Python For Loops Tutorial For Loop Through a String For Break For Continue Looping Through a rangee For Else Nested Loops ... If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail: sales@w3schools.com
🌐
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.
🌐
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.
🌐
Programiz
programiz.com › python-programming › pass-statement
Python pass Statement (With Examples)
In this tutorial, we'll learn about the pass statement in Python programming with the help of examples.
🌐
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":
Find elsewhere
🌐
W3Schools
w3schools.com › python › gloss_python_function_arguments.asp
Python Function Arguments
Python Functions Tutorial Function Call a Function *args Keyword Arguments **kwargs Default Parameter Value Passing a List as an Argument Function Return Value The pass Statement i Functions Function Recursion ... If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail: sales@w3schools.com
🌐
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
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”)

🌐
LearnDataSci
learndatasci.com › solutions › python-pass
Python pass statement: When, why, and how to use it – LearnDataSci
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). This functionality may seem pointless, but let's try and run our example from the introduction again, without ...
🌐
W3Schools
w3schools.com › python › python_functions.asp
Python Functions
The pass statement is often used when developing, allowing you to define the structure first and implement details later. ... If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail: ...
🌐
Cach3
w3schools.com.cach3.com › python › ref_keyword_pass.asp.html
Python pass Keyword - W3Schools
Python Overview Python Built-in ... · Python Examples Python Exercises Python Quiz Python Certificate ... The pass statement is used as a placeholder for future code....
🌐
DataCamp
datacamp.com › tutorial › python-pass
How to Use the Python pass Statement | DataCamp
July 11, 2024 - This use case ensures you can define the functions, classes, or loops and then include the body later when required. The examples below show the code error in an empty loop and successful code execution using the pass statement. # An empty function will return an error def some_function(): Python output showing function with pass statement.
🌐
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 ...
🌐
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.
🌐
Python.org
discuss.python.org › python help
Can someone please explain the pass statement? - Python Help - Discussions on Python.org
January 26, 2023 - I’m just wondering what the purpose of the pass statement is and how its used. The answers I’ve found are vague saying it does nothing- so what is it used for? Any examples? Thanks! Dave
🌐
Real Python
realpython.com › ref › keywords › pass
pass | Python Keywords – Real Python
Creating minimal class or function ... ... In this tutorial, you'll learn about the Python pass statement, which tells the interpreter to do nothing....