Pass Statement In Python Programming Language

Pass Statement In Python Programming Language

In this article, you will learn how to use pass statement in Python programming language efficiently and without any error.

This is a step by step easy to understand tutorial that will teach you how to use pass statement in Python programming language.

In this article, you will learn the following things.

What is Pass Statement In Python programming language?

Unlike other statements in Python programming language like break and continue statements where the iteration of loop or flow of statement terminates or skip respectively, the pass statement works differently.

Pass statement in Python programming language is doing nothing in the execution process so, basically, it is a null and void operation in the execution of code.

Recommended:  Introduction And Features Of Python Programming Language

Maybe a question arises like is pass statement is as same as a comment? the answer is it looks the same but there is a slight difference between both of them.

When we use the comment in our code the comment is ignored by the compiler or interpreter completely but the pass statement is not ignored by compiler or interpreter but however, there is no impact of Pass statement in code execution. It is basically a null statement.

Syntax of Pass statement in Python programming language

Practical examples of Pass statement in Python programming language

In the above example, we write a string as WalkIntoPC and we run a for a loop. In the for loop, we set a condition that in the loop if letter “n” encounter the control hands over to the pass statement.

The Pass statement does nothing but after the execution of the Pass statement, the control of the program goes back to the for loop.

There is one other scenario in which suppose you have for loop but you don’t want to put any values in it and use it in the future.

If you leave the loop blank you get an error but fortunately, we have a solution for it and it is the Pass statement.  We set the Pass statement in the loop body and leave it as it is for future use.  See the example below.

Recommended:  Keywords And Identifiers In Python Programming Language

Use of Python Pass statement in While loop


Like using Pass statement in for loop we can use Pass statement in while loop also.

Use of Python Pass statement in If Else statement

We can use Python Pass statement in If else statement as follows.

 

Jack Sparrow

Hay I Am Admin Of This Website. I Am Very Passionate About Computers And Technology. This Website Is The Result Of My Passion. I Love To Eliminate The Barriers That Come In Seeking Education. This Website Is The Free Source Of Learning About New Technology And Up To Date Knowledge.

Leave a Reply

Close Menu