Python pass Statement and Uses In The Coding to Write No Statement

In Python pass Statement and Uses In The Coding to Write No Statement when need to implement a blank block and/or a blank loop.It is used when a statement is required syntactically but you do not want any command or code to execute.

The pass statement is a null operation; nothing happens when it executes. The pass is also useful in places where your code will eventually go, but has not been written yet (e.g., in stubs for example):

Syntax

pass

Example

#!/usr/bin/python

for letter in 'Python': 
   if letter == 'h':
      pass
      print 'This is pass block'
   print 'Current Letter :', letter

print "Good bye!"

When the above code is executed, it produces following result −

Current Letter : P
Current Letter : y
Current Letter : t
This is pass block
Current Letter : h
Current Letter : o
Current Letter : n
Good bye!
 If you have any further clarification on this topic please give comment below on the Python pass Statement and Uses In The Coding to Write No Statement

You may also like...

Leave a Reply

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