Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

python
pass

What is pass statement in Python?

Educative Answers Team

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

In Python, pass is a null statement. The interpreter does not ignore a pass statement, but nothing happens and the statement results into no operation.

The pass statement is useful when you don’t write the implementation of a function but you want to implement it in the future.

So, to avoid compilation errors, you can use the pass statement.

svg viewer

Syntax

The syntax of the pass statement is:

   pass

Example

1 of 7

Writing a function with no body

addition() function has no implemention:

def addition(num1, num2):
# Implementation will go here
pass # Pass statement
addition(2, 2)

Ignoring an if statement implementation

if statement has no implementation:

# This functions prints the number if its not 2
def display(number):
if number is 2:
pass # Pass statement
else:
print ("Number: ", number)
display(2)
display(3)

RELATED TAGS

python
pass
Copyright ©2022 Educative, Inc. All rights reserved

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring