In Python, the pass
statement does nothing when it's executed. It is typically used as a placeholder (for future code) in places where a statement is required syntactically (such as in loops, function and class definitions, if statements, etc.).
For example, the following function does nothing when executed; it is merely meant as a placeholder:
def foo(): pass print(foo()) # None
Consider the following class that has no methods yet, and is defined as a placeholder:
class Foo: pass foo = Foo() print(foo) # <__main__.Foo object at ...>
You could use pass
in an if
statement as well, where the code for it might not be ready yet:
n = 0 if n == 0: pass else: print("n is not 0")
Similarly, you can use the pass
statement to act as a placeholder in other places where empty code is not allowed, so that the code execution can pass without raising any errors.
Hope you found this post useful. It was published . Please show your love and support by sharing this post.