🌐
LearnDataSci
learndatasci.com › solutions › python-pass
Python pass statement: When, why, and how to use it – LearnDataSci
We can avoid this error by using pass as a placeholder for our elif statement as seen in the introduction. The addition of pass means that Python does nothing in situations where the number variable isn't a multiple of 27. Despite this seeming redundant, it prevents Python from throwing an error. The flowchart shown below helps demonstrate how pass is working here:
🌐
Programiz
programiz.com › python-programming › pass-statement
Python pass Statement (With Examples)
Here, notice that we have used the pass statement inside the if statement . However, nothing happens when the pass is executed. It results in no operation (NOP). Suppose we didn't use pass or just put a comment as:
Discussions

python - How to use "pass" statement? - Stack Overflow
I am in the process of learning Python and I have reached the section about the pass statement. The guide I'm using defines it as being a null statement that is commonly used as a placeholder. I st... More on stackoverflow.com
🌐 stackoverflow.com
Can someone please explain the pass statement?
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 More on discuss.python.org
🌐 discuss.python.org
0
1
January 26, 2023
How can I create a flowchart from a Python code?
Some info in https://www.reddit.com/r/learnpython/s/o6xiWD1HAj but are you wanting something that you use to generate a diagram or one that represents the program flow of your code? More on reddit.com
🌐 r/learnpython
7
3
November 28, 2024
Create diagram/flowchart of the script
Automatically? Not that I am aware of. If you're looking for software that will allow you to draw a flowchart, diagrams.net is a decent, free resource. Edit: there's pyflowchart , but I have never used it so can't vouch for it at all. More on reddit.com
🌐 r/learnpython
11
1
April 19, 2023
🌐
Tutorialspoint
tutorialspoint.com › python › python_pass_statement.htm
Python - pass Statement
For instance, in a function or class definition where the implementation is yet to be written, pass statement can be used to avoid the SyntaxError. Additionally, it can also serve as a placeholder in control flow statements like for and while loops. Following is the syntax of Python pass statement −
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-pass-statement
Python pass Statement - GeeksforGeeks
It is used to keep code blocks valid where a statement is required but no logic is needed yet. Examples situations where pass is used are empty functions, classes, loops or conditional blocks.
Published   October 4, 2025
🌐
TOOLSQA
toolsqa.com › python › python-break-continue-and-pass-statements
Python Break Statement, Continue and Pass - Loop Control Statements
August 6, 2021 - The flowchart of the Python continue ... Something that will do nothing!! Python pass statement is an empty check which does not interrupt the normal flow of the loop....
🌐
Scientech Easy
scientecheasy.com › home › blog › python pass statement
Python Pass Statement - Scientech Easy
February 28, 2025 - Let’s take an example to understand the pass statement. ... Here, pass is a keyword in Python. Look at the below flowchart diagram of pass statement.
🌐
Shiksha
shiksha.com › home › it & software › it & software articles › programming articles › python pass statement: a simple solution for placeholder code blocks
Python Pass Statement: A Simple Solution for Placeholder Code Blocks - Shiksha Online
October 18, 2023 - What is a pass statement in Python? Flowchart of a pass statement in Python · Syntax · Comparison of pass statement with other Python tools · Best practices of using pass statement in Python · Recommended online courses · Learn Python with these high-rated online courses ·
🌐
Scribd
scribd.com › document › 544532570 › unit-2-long
Python Control Flow Statements Explained | PDF | Control Flow | Computing
The document discusses 6 different types of flow control statements in Python: 1) if-else, 2) nested if-else, 3) for loops, 4) while loops, 5) break statements, and 6) continue statements. Each statement is explained with its syntax and a flowchart example. Additionally, the PASS statement ...
Find elsewhere
🌐
Real Python
realpython.com › python-pass
The pass Statement: How to Do Nothing in Python – Real Python
September 25, 2023 - The statements inside this type of block are technically called a suite in the Python grammar. A suite must include one or more statements. It can’t be empty. To do nothing inside a suite, you can use Python’s special pass statement. This statement consists of only the single keyword pass.
🌐
Toppr
toppr.com › guides › python-guide › tutorials › python-flow-control › python-pass-statement
Python Pass: Pass statement in Python, Pass function Python
October 18, 2021 - The pass statement does not get ignored by the Python compiler. Instead, it gets executed by just skipping past the loop condition, function, or class. When the pass statement is executed, it results in no operation.
🌐
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.
🌐
W3Schools
w3schools.com › python › ref_keyword_pass.asp
Python pass Keyword
Python Examples Python Compiler ... Bootcamp Python Certificate Python Training ... 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 - The Python Cheat Sheet for Beginners will also help refresh your skills and guide you during the learning. The simplest way to use the pass statement in Python is to place it in any code block that you want to leave empty.
🌐
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).
🌐
STechies
stechies.com › python-pass-statement
How to Use the Pass Statement in Python?
This tutorial explains what is pass statement in python, use of pass statement in python, examples of pass statement with 'if statement', the difference between pass vs return statement and the difference between pass vs continue statement in Python.
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”)

🌐
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
🌐
Programiz PRO
programiz.pro › resources › python-pass
Python pass Statement
December 10, 2024 - The pass statement in Python acts as a placeholder that allows you to create empty functions, loops, or conditional blocks without causing an error.
🌐
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 place of the function body, indicating that we do not know what the function should do yet. Similarly, in the second line of the code, we have defined a loop with the pass statement in the loop body.
🌐
Analytics Vidhya
analyticsvidhya.com › home › python pass statement
Python pass Statement
January 27, 2025 - Learn how to use the Python pass statement with syntax, examples, and best practices. Understand use in functions, loops, and conditionals.