In Python, the pass statement is used when a statement is required syntactically, but no command or code must be executed. It specifies a null operation or simply No Operation statement. Nothing happens when the pass statement is executed.
Actually, the pass statement is used as a placeholder. For example, if we have a loop that is not implemented yet, but we may wish to write some code in it in the future. In such cases, a pass statement can be written because we cannot have an empty body of the loop. The pass statement is not done anything, but it can make the program syntactically correct.
The syntax of the pass statement is given below:
pass
Example 1:
a="welcome" for i in a: pass #Here pass statement is doing nothing print(i,end=" ") print("Done")
Output:
w e l c o m e Done
Example 2:
a="This is Python" s="" for i in a: if(i=='a' or i=='e' or i=='i' or i=='o' or i=='u'): pass else: s=s+i #removing vowels print(s)
Output:
Ths s Python
Leave a comment