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