Overview
pass is a keyword in Python.
pass keyword constitutes a pass statement.
pass denotes a null operation. Nothing happens when pass is executed.
pass is not equivalent to a comment statement in Python.
Unlike a comment statement a pass statement in Python is not ignored.
In function blocks, method blocks, if blocks and for blocks - a Python developer can use a statement alone denoting the implementation of the block is to be done later.
Blocks only with pass statements make the design intentions of the developer clear and explicit.
A function or method with a pass statement returns None.
Example 1
def mean():
pass
z = mean()
print(z)Output
NoneThe above definition of function mean()is deferred with a pass statement.
Example 2
class image:
def translate(self):
print("translation done") # the real implementation will be much more
def rotate(self):
print("rotation done") # the real implementation will be much more
def add(self):
pass # adding two images is for sprint 2
imageObject = image()
# Test image operations
imageObject.translate()
imageObject.rotate()
imageObject.add()Output
translation done
rotation doneIn the above example implementation rotation method of an image object is marked for sprint 2 and filled with a pass statement.