Showing posts with label Python: Pass Statement. Show all posts
Showing posts with label Python: Pass Statement. Show all posts

Python: Pass Statement

 Pass statement is interpreted as a placeholder for future functions, classes, loops and other operations.

Pass statement is also known as the null statement. We can use the pass statement as a placeholder when unsure of the code to provide. Therefore, the pass only needs to be placed on that line. The pass is utilized on that place where we want no code to be executed. We can simply insert a pass in cases where empty code is prohibited. Such as in loops, functions, class definitions and if-else statements.

Ordinarily, we use it as a perspective for what's to come.

Let's understand, we have an if-else statement or a loop that we want to fill in the future. An empty body for the pass keyword would be grammatically wrong. A mistake would be shown by the Python translator proposing to occupy the space. As a result, we use the pass statement to create a code block that does nothing. 

Use of the Pass statement:

Code:

# Python program to show the use of the Pass statement in for loop
#Pass statement is used here as a placeholder, which can be filled later on
sequence = {"Python", "Pass", "Statement", "Placeholder"}
for value in sequence:
    if value=="Pass":
        Pass
    else:
        print("Not reached pass keyword:", value)


Output:

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

Python: Functions