Python pass Statement Last Updated : 04 Jan, 2025 Comments Improve Suggest changes Like Article Like Report 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. It does nothing but allows us to maintain the structure of our program.Example Use of Pass Keyword in a FunctionPass 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. Python # Example of using pass in an empty function def fun(): pass # Placeholder, no functionality yet # Call the function fun() Explanation:function fun() is defined but contains the pass statement, meaning it does nothing when called.program continues execution without any errors and the message is printed after calling the function.Let's explore other methods how we can use python pass statement:Table of ContentUsing pass in Conditional StatementsUsing pass in LoopsUsing pass in ClassesUsing pass in Conditional StatementsIn a conditional statement (like an if, elif or else block), the pass statement is used when we don't want to execute any action for a particular condition. Python x = 10 if x > 5: pass # Placeholder for future logic else: print("x is 5 or less") OutputExplanation:When x > 5, the pass statement is executed, meaning nothing happens.If x <= 5, the else block runs, printing "x is 5 or less".pass allows the code to compile and run without errors, even though the if block is currently empty.Using pass in LoopsIn loops (such as for or while), pass can be used to indicate that no action is required during iterations. Python for i in range(5): if i == 3: pass # Do nothing when i is 3 else: print(i) Output0 1 2 4 Explanation:The loop iterates through numbers from 0 to 4.When i == 3, the pass statement is executed, meaning no action is taken for that iteration.For other values of i, the number is printed.Using pass in ClassesIn classes, pass can be used to define an empty class or as a placeholder for methods that we intend to implement later. Python class EmptyClass: pass # No methods or attributes yet class Person: def __init__(self, name, age): self.name = name self.age = age def greet(self): pass # Placeholder for greet method # Creating an instance of the class p = Person("Anurag", 30) Explanation:EmptyClass is defined but has no methods or attributes. The pass statement is used to define an empty class.In the Person class, the greet method is defined, but it does nothing yet (as indicated by pass).This allows us to define the class and method structure without having to implement the logic immediately. Comment More infoAdvertise with us Next Article Python pass Statement T taran910 Follow Improve Article Tags : Python python-basics python Practice Tags : pythonpython Similar Reads Python break statement The break statement in Python is used to exit or "break" out of a loop (either a for or while loop) prematurely, before the loop has iterated through all its items or reached its condition. When the break statement is executed, the program immediately exits the loop, and the control moves to the nex 5 min read Python Match Case Statement Introduced in Python 3.10, the match case statement offers a powerful mechanism for pattern matching in Python. It allows us to perform more expressive and readable conditional checks. Unlike traditional if-elif-else chains, which can become unwieldy with complex conditions, the match-case statement 7 min read Jump Statements in Python In any programming language, a command written by the programmer for the computer to act is known as a statement. In simple words, a statement can be thought of as an instruction that programmers give to the computer and upon receiving them, the computer acts accordingly. There are various types of 4 min read Python return statement A return statement is used to end the execution of the function call and it "returns" the value of the expression following the return keyword to the caller. The statements after the return statements are not executed. If the return statement is without any expression, then the special value None is 4 min read Nested-if statement in Python For more complex decision trees, Python allows for nested if statements where one if statement is placed inside another. This article will explore the concept of nested if statements in Python, providing clarity on how to use them effectively.Python Nested if StatementA nested if statement in Python 2 min read Like