What is the use of Pass statement in Python?

The use of Pass statement is to do nothing. It is just a placeholder for a statement that is required for syntax purpose. It does not execute any code or command.

Some of the use cases for pass statement are as follows:

  • Syntax purpose:
    >>> while True:
    … pass # Wait till user input is received
  • Minimal Class: It can be used for creating minimal classes:
    >>> class MyMinimalClass:
    … pass
  • Place-holder for TODO work:
    We can also use it as a placeholder for TODO work on a function or code that needs to be implemented at a later point of time.
    >>> def initialization():
    … pass # TODO

Read the full book at www.amazon.com
Posted in Python, Python Interview Questions

Leave a Reply

Your email address will not be published. Required fields are marked *

*