DEV Community

Cover image for PASS With IF ELSE In PYTHON
Sakshi
Sakshi

Posted on

PASS With IF ELSE In PYTHON

PYTHON UNLEASH'D 02

As discussed in prev blog, conditional statement can make use of pass.

What is Pass?

Pass is used as placeholder inside if statement.
When pass is encountered no action is taken, but program will not generate any error as there is one statement i.e, pass written there, which tells it is not empty.

Also we can write pass, when we want to add the code later, after some time depending on next parts of program. To escape from error, we can write pass.

Note that in all cases, the pass statement is followed by a colon (:) to indicate the start of a code block, but there is no code inside the block. This is what makes it a placeholder statement.

The below snippet from Geeks For Geeks show a good example on how we can use pass in if statement, function and class.

# Using pass as a placeholder inside an if statement
x = 5
if x > 10:
    pass
else:
    print("x is less than or equal to 10")

# Using pass in a function definition as a 
# placeholder for implementation
def my_function():
    pass

# Using pass in a class definition as
# a placeholder for implementation

class MyClass:
    def __init__(self):
        pass

Enter fullscreen mode Exit fullscreen mode

Top comments (0)