Python Pass Statement
In Python programming, pass
is a null statement typically used as a placeholder. In contrast to a comment
statement which is ignored by the Python interpreter, a pass
statement is not ignored but nothing happens when it is executed. It results in No Operation (NOP).
Consider the case of a loop or function that we have not fully implemented yet. Without a body, the Python interpreter will complain but with a pass
statement we can return to it later.
while True:
pass
letters = ['a', 'b', 'c', 'd', 'e']
for l in letters:
pass
pass
statements are frequently used with functions and classes when you want to continue thinking at a more abstract level and later implement the code in full:
def function(args):
pass # Remember to implement later
class EmptyClass:
pass
Want to improve your Python? I have a list of recommended Python books.