In this tutorial, we will learn all about the python pass function.
What is Python pass function
Pass in python is used as a placeholder for future statements and code. Python pass function the null statement which does nothing in python. The null statement will return nothing or null when we execute a pass statement.
The python pass function is useful when you are dealing with very large code when you have to work on multiple conditional statements, loops, or in-class and custom functions.
The syntax of the pass functions is:
Let see an example of a pass function with if..else conditional statement.
As we can see it’s not giving any result when the given conditional is true but as we are using pass function it is passing the flow to the next piece of code.
Python pass function with for loop
We can also use pass function within the for and while loops.
When we execute the program we will get the output:
As we can see we are printing letters using for loop and we have given the condition that if letter equal to h statement inside the if conditional should be executed and when the conditional get true we are calling pass statement and a print statement and as we can see python is skipping the pass statement and just print the given string inside the if condition.
Python pass statement with the while loop
As we know there are two loops in python, so just like for loop we can also use the same with while loop as follows.
Example of While loop with pass function.
As we can see it not returning any output because we have use pass function within the first statement inside the while loop.
Python pass statement with functions
We can use pass function in custom functions also, you can learn more about functions in upcoming tutorials.
Python pass statement with class
Just like a function, we can use a pass function in class also.