Python pass statement

The Python pass statement does nothing. You can use it when a statement is required but the program need not do anything. Suppose if you want to define an empty function you can use the pass statement.

>>> def empty():
 pass

>>> empty() #does nothing

The most common use of pass statement is to create a minimal class: a class containing nothing.

>>> class empty_class:
	pass

Using pass otuside a function

If you use the pass statement outside the function then the program will get hang. To get out of this situation or interupt the program you have to press ‘Ctr+C‘.

>>> while True:
	pass

Traceback (most recent call last):
  File "<pyshell#19>", line 2, in <module>
    pass
KeyboardInterrupt




Leave a Reply

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