Python pass Statement - pass in Python With Examples

Dear learners, how is everything going? Hope that you’re learning well. In our previous tutorial, we learned about Python break and continue statement to control python loops. You can find that tutorial here. In this tutorial, we are going to learn about Python pass statement.

Python pass statement

You can consider python pass statement as no operation statement. The difference between Python comments and pass statement is; comments are being eliminated while interpreting the program but pass statement does not. It consumes execution cycle like a valid statement. For example, for printing only the odd numbers from a list, our program flow will be:

Now if we convert the above things to python,

The output will be

Suppose you need to implement many function one by one. But you have to check every function after implementing the function. Now if you leave the things like this:

Then, you will get IndentationError for this.

Python pass statement

So, what you need to do is, add pass statement to each no-implemented function like this.

For the above code, you will get output like this

Why should we use Python pass Statement

Now, a question may come to your mind, why should we use Python pass statement? Actually it seems that, in our previous example, if we just comment-out the unimplemented functions, like below, we will still get our desired output.

But if you work with a huge python project, at one time, you may need something like pass statement. That’s why pass statement is introduced in Python.

That’s all for today. Hope that, you learned well about Python pass statement. Stay tuned for our next tutorial and for any confusion, feel free to use the comment box.

Reference: Official Documentation

By admin

Leave a Reply