Lesson 25 of 70 – Python Pass Statement
36%

Python Pass Statement

The pass statement is a special statement in Python that does nothing. It is used as a placeholder when a statement is required syntactically, but no action needs to be performed yet.

Note: Unlike break and continue, the pass statement does not stop or skip a loop. It simply does nothing.
What is the Pass Statement?

The pass statement tells Python to do nothing at that point.

pass

It is useful when you want to write the structure of a program first and add the actual code later.

Simple Pass Example
if True:
    pass

print("Program continues")
Output:
Program continues

The pass statement does nothing, so Python continues with the next statement.

Why Use Pass?

Python requires an indented statement inside structures such as if statements, loops, functions, and classes.

If you do not want to write any action yet, you can use pass.

if age >= 18:
    pass

This is valid Python code.

Pass in If Statement
age = 20

if age >= 18:
    pass

print("Program continues")
Output:
Program continues

The if condition is True, but pass tells Python to do nothing inside the if block.

Pass in Else Statement
age = 20

if age >= 18:
    print("Adult")
else:
    pass
Output:
Adult
Pass in For Loop
for i in range(5):

    if i == 2:
        pass

    print(i)
Output:
0
1
2
3
4

The pass statement does not skip the value 2. The print statement still executes.

Pass in While Loop
i = 1

while i <= 5:

    if i == 3:
        pass

    print(i)
    i += 1
Output:
1
2
3
4
5
Pass vs Continue

Using pass:

for i in range(5):

    if i == 2:
        pass

    print(i)
Output:
0
1
2
3
4

Using continue:

for i in range(5):

    if i == 2:
        continue

    print(i)
Output:
0
1
3
4

pass does nothing, while continue skips the current iteration.

Pass vs Break

Using pass:

for i in range(5):

    if i == 2:
        pass

    print(i)

Using break:

for i in range(5):

    if i == 2:
        break

    print(i)
Break Output:
0
1

The break statement stops the loop, while pass allows the loop to continue normally.

Pass in Function

The pass statement can be used when creating a function whose implementation will be added later.

def calculate():
    pass

print("Function created")
Output:
Function created

The function exists, but it does not perform any action.

Pass in Class

The pass statement can also be used when defining an empty class.

class Student:
    pass

student = Student()

print("Student object created")
Output:
Student object created
Empty Function with Pass
def welcome():
    pass

welcome()

print("Done")
Output:
Done

The function executes but has no action because it contains only pass.

Pass in Empty Loop
for i in range(5):
    pass

print("Loop finished")
Output:
Loop finished

The loop runs, but its body performs no operation.

Pass for Future Development

Sometimes developers create the structure of a program before implementing every feature.

def login():
    pass

def register():
    pass

def logout():
    pass

Later, actual code can be added inside these functions.

Pass in Conditional Code
marks = 75

if marks >= 40:

    if marks >= 80:
        print("Excellent")
    else:
        pass

else:
    print("Fail")
Output:
No output

Here, marks are between 40 and 79, so the inner else block executes pass and nothing is printed.

Pass in Nested Conditions
number = 10

if number > 0:

    if number < 20:
        pass

print("Completed")
Output:
Completed

The inner condition performs no action because it contains pass.

Pass with User Input
age = int(input("Enter age: "))

if age < 18:
    pass
else:
    print("Adult")

If the user enters 15, nothing is printed. If the user enters 20, the output is:

Adult
Pass in Exception Handling

The pass statement can also be used inside an exception handler when you intentionally do not want to take any action.

try:
    number = int("abc")

except ValueError:
    pass

print("Program continues")
Output:
Program continues
Pass with Multiple Conditions
number = 10

if number > 0:
    pass
elif number == 0:
    print("Zero")
else:
    print("Negative")

print("Done")
Output:
Done

The first condition is True, so Python executes pass and then continues after the complete if-elif-else structure.

Pass in Nested Loop
for i in range(3):

    for j in range(3):

        if i == j:
            pass

        print(i, j)
Output:
0 0
0 1
0 2
1 0
1 1
1 2
2 0
2 1
2 2

The pass statement does not affect the loop execution.

What Happens Without Pass?

Consider this code:

if age >= 18:

This produces an indentation or syntax-related error because Python expects an indented statement after the colon.

Using pass solves this problem:

if age >= 18:
    pass
Pass vs Break vs Continue
Statement Purpose
pass Does nothing.
continue Skips the current iteration.
break Stops the loop completely.
Real-Life Example

Suppose we are designing a student management system and want to create functions first. We can use pass until their logic is implemented.

def add_student():
    pass

def update_student():
    pass

def delete_student():
    pass

def view_student():
    pass

Later, actual functionality can be added to each function.

Important Rules
  • pass does nothing.
  • It is a valid Python statement.
  • It is useful as a placeholder.
  • It can be used inside if statements.
  • It can be used inside loops.
  • It can be used inside functions.
  • It can be used inside classes.
  • It can be used inside exception handlers.
  • It does not stop a loop.
  • It does not skip an iteration.
Key Points
  • The pass statement does nothing.
  • It is mainly used as a placeholder.
  • It helps create incomplete program structures without syntax errors.
  • It can be used with if, for, while, functions, classes, and exceptions.
  • Pass is different from break.
  • Pass is different from continue.
  • Pass allows normal program execution to continue.

🧠 Quick Quiz

Question: What does the pass statement do in Python?