Python 3 – pass
Statement
In Python 3, pass
is a statement that does nothing. It is used when a statement is required syntactically but you don’t want to do anything. It can also be used as a place holder for code that will eventually be written.
The pass
statement can be used in the following cases:
- Empty function: In some cases, you may want to create a function that currently does nothing. In such cases, you can use the
pass
statement to indicate that the function is empty.
def emptyFunction():
pass
- Empty loop: The
pass
statement can be used in cases where you want an empty loop i.e. a loop that does nothing.
for i in range(10):
pass
- Placeholder statement: In some cases, you may want to leave a placeholder in your code for future use. In such cases, you can use the
pass
statement until you’re ready to add real code.
if True:
pass # TODO: add code later
Conclusion
In conclusion, the pass
statement in Python 3 is a statement that does nothing. It can be used as a placeholder for code that will eventually be written or in cases where a statement is required syntactically but you don’t want to do anything.