🌐
Built In
builtin.com › software-engineering-perspectives › pass-vs-continue-python
Pass vs. Continue in Python Explained | Built In
Pass and continue are two statements in Python that alter the flow of a loop. Pass signals that there’s no code to execute, while continue forces the loop to skip the remaining code and start a new statement. Here’s what you need to know.
🌐
W3Schools
w3schools.com › python › gloss_python_for_pass.asp
Python The pass Keyword in For Loops
Python Examples Python Compiler ... you for some reason have a for loop with no content, put in the pass statement to avoid getting an error....
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
Is there a difference between "pass" and "continue" in a for loop in Python? - Stack Overflow
In those examples, no. If the statement is not the very last in the loop then they have very different effects. ... Pass: Python works purely on indentation! More on stackoverflow.com
🌐 stackoverflow.com
Python Break, Continue, Pass Statements with Examples
A complete guide to Python break, continue, and pass statements with examples, best practices, and real-world use cases. More on accuweb.cloud
🌐 accuweb.cloud
1
December 11, 2023
Unravelling the `pass` statement
omg it literally does nothing.... More on reddit.com
🌐 r/Python
24
283
May 15, 2021
🌐
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. Suppose we have a loop or a function that is not implemented yet, but we want to implement it in the future.
🌐
Real Python
realpython.com › python-pass
The pass Statement: How to Do Nothing in Python – Real Python
September 25, 2023 - After the for statement is the body of the for loop, which consists of the two indented lines immediately following the colon. In this case, there are two statements in the body that are repeated for each value: ... 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.
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-pass-statement
Python pass Statement - GeeksforGeeks
The pass statement in Python is a placeholder that does nothing when executed. 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, ...
Published   October 4, 2025
🌐
Tutorialspoint
tutorialspoint.com › python › python_pass_statement.htm
Python - pass Statement
for letter in 'Python': if letter == 'h': pass print ('This is pass block') print ('Current Letter :', letter) print ("Good bye!") When the above code is executed, it produces the following output − · Current Letter : P Current Letter : y Current Letter : t This is pass block Current Letter : h Current Letter : o Current Letter : n Good bye! This is simple enough to create an infinite loop using pass statement in Python.
🌐
Python documentation
docs.python.org › 3 › tutorial › controlflow.html
4. More Control Flow Tools — Python 3.14.3 documentation
When used with a loop, the else ... For more on the try statement and exceptions, see Handling Exceptions. The pass statement does nothing....
🌐
DigitalOcean
digitalocean.com › community › tutorials › how-to-use-break-continue-and-pass-statements-when-working-with-loops-in-python-3
How to Break Out of Multiple Loops in Python | DigitalOcean
August 7, 2025 - The continue statement skips the rest of the current iteration and moves to the next cycle of the loop, helping avoid deeply nested conditionals and improve loop clarity. The pass statement is a syntactic placeholder that performs no action, commonly used when a block of code is syntactically ...
Find elsewhere
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”)

🌐
iO Flood
ioflood.com › blog › python-pass
Python 'pass' Statement | Guide (With Examples)
June 7, 2024 - In Python, the ‘pass’ statement is a null operation. When it’s executed, nothing happens. It’s a placeholder and is used where the syntax requires a statement, but you don’t want any command or code to be executed.
🌐
GeeksforGeeks
geeksforgeeks.org › python › break-continue-and-pass-in-python
Loop Control Statements - Python
July 12, 2025 - Python Continue statement is a ... the next iteration of the loop will begin. ... Pass statement in Python is a null operation or a placeholder....
🌐
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).
🌐
DataCamp
datacamp.com › tutorial › python-pass
How to Use the Python pass Statement | DataCamp
July 11, 2024 - The Python pass statement serves as a placeholder in situations where a statement is syntactically necessary, but no actual code is needed. The pass statement is a null operation that returns nothing when executed in a code block.
🌐
Educative
educative.io › answers › what-is-pass-statement-in-python
What is pass statement in Python?
Comments (using #) are ignored by Python during execution and are used for documentation purposes, whereas the pass statement is an actual statement that tells Python to do nothing but keeps the structure of the code valid.
🌐
Unstop
unstop.com › home › blog › python pass statement | uses, alternatives & more (+examples)
Python Pass Statement | Uses, Alternatives & More (+Examples)
October 21, 2024 - Inside the loop, we use the pass statement, which will indicate that no operation is performed during each iteration. As a result, the loop runs five times, but nothing happens in the loop body.
🌐
W3Schools
w3schools.com › python › python_if_pass.asp
Python Pass Statement
You need pass where Python expects a statement, not just a comment. ... You can use pass in any branch of an if-elif-else statement. ... value = 50 if value < 0: print("Negative value") elif value == 0: pass # Zero case - no action needed else: print("Positive value") Try it Yourself » · While we focus on pass with if statements here, it's also commonly used with loops, functions, and classes.
🌐
Accuweb
accuweb.cloud › home › python break, continue, pass statements with examples
Python Break, Continue, Pass Statements with Examples
December 11, 2023 - The pass statement is different from break and continue because it does nothing at all. It acts as a placeholder statement where Python requires code syntactically but you do not want to execute anything yet.
🌐
W3Schools
w3schools.com › python › ref_keyword_pass.asp
Python pass Keyword
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. Empty code is not allowed in loops, function definitions, class ...
🌐
Alma Better
almabetter.com › bytes › tutorials › python › break-pass-continue-statement-in-python
Break, Pass, and Continue Statements in Python
April 25, 2024 - ... What does the pass statement do in Python? 1. Exits the current loop and resumes execution at the next statement. 2. Skips the current loop and resumes execution at the next iteration.