Python pass Statement Explained with Examples

Python pass statement is a null operation. It is used when a statement is required syntactically but you do not want any command or code to execute.

Pass in Function

Pass statement often used in a function. You can use it to create an empty function.

def my_function():
    pass  # Placeholder for future implementation

Pass in Condition Statement

It is used as a placeholder when a statement is syntactically required but no action is needed.

if x < 5:
    pass  # Placeholder for future code implementation

Pass in Class

Similar to pass in function, you can use pass statement to create an empty class.

class MyClass:
    pass  # Class definition to be filled later