Sunday, October 25, 2020

pass keyword in python

Python programming do not allow empty block of code within a program. pass is a syntactical requirement of python programming to write future code. Empty block of code is not allowed in loops, function definitions, conditional statements, class definitions.
Let us try few examples with empty block of code and introduce pass later.

Copy the below code into a program called pass.py and execute it. printData function do not have any statements.

def printData():

    
def main():
    printData()

if (__name__ == '__main__'):
    main()


Execution of the program is showing indentation error at function main. Now let us introduce pass in printData function and re-execute the program.


def printData():
    pass
    
def main():
    printData()

if (__name__ == '__main__'):
    main()


After introducing pass keyword program executed without any errors. Similarly empty blocks are not allowed for loops, function definitions, conditional statements, class definitions.

Code can be downloaded from GitHub

No comments:

Post a Comment

Operations on Python Dictionaries