A pass statement is an empty/null statement that is considered as a placeholder for future code. When a user doesn’t want to write a code, or is not able to write a code under a particular class or function, the user can apply a pass statement.
Empty code shouldn’t be included in loops, function definitions, class definitions, or if statements because there is a possibility that it will cause an error. To avoid errors, the user can simply apply a pass statement.
In the code snippet below, our code is in the else
block, but because of the pass
statement, no operation is performed.
Remember: The
pass
statement is a placeholder for future code; so, we can replace it whenever we have to do an operation in thiselse
block.
lst = [1, 2, 3] value = 5 if value in lst: print('Its in the list') else: pass print('Execution completed')
RELATED TAGS
CONTRIBUTOR
View all Courses