Javatpoint Logo
Javatpoint Logo

Python Pass Statement

We will discover more about pass statements in this tutorial. It is interpreted as a placeholder for the future execution of functions, classes, loops, etc.

What is Pass Statement in Python?

The null statement is another name for the pass statement. A Comment is not ignored by the Python interpreter, whereas a pass statement is not. Hence, they two are different Python keywords.

We can use the pass statement as a placeholder when unsure what code to provide. So, we only have to place the pass on that line. Pass may be used when we don't wish any code to be executed. We can simply insert a pass in places where empty code is prohibited, such as loops, functions, class definitions, or if-else statements.

Syntax of the Pass Keyword

Typically, we utilise it as a reference for the future.

Let's say we have a loop or an if-else statement that isn't to be filled now but that we wish to in the future. The pass keyword cannot have an empty body as it will be syntactically wrong. An error would be displayed by the Python interpreter suggesting to fill the space. Therefore, we create a code block that performs nothing using the pass statement.

Example of the Pass Statement

Code

Output:

Not reached pass keyword:  Python
Not reached pass keyword:  Placeholder
Not reached pass keyword:  Statement

The same thing is also possible to create an empty function or a class.

Code


Next TopicPython Strings





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA