Python Program for Pass Statement with Examples

pass Statement in Python:

The pass statement serves as a placeholder for additional code.

The pass statement is a null statement in Python programming. The difference between a comment and a pass statement in Python is that while a comment is completely ignored by the interpreter, a pass statement is not.

When the pass is executed, however, nothing happens. It has no effect on the operation (NOP).

Assume we have a loop or a function that has not yet been implemented but that we intend to do so in the future. They cannot exist with an empty body. The interpreter would return an error message. As a result, we use the pass statement to create a body that does nothing.

Syntax:

pass
In a function definition, use the pass keyword as follows:

Example:

# Without the pass statement, having an empty function definition like this
# would result in an error.
def empty_function():
    pass

Output:


Explanation:

we don't get any output since it is an empty function.But, Without the pass 
statement, having an empty function definition like this would 
result in an error.
In a class definition, use the pass keyword as follows:

Example:

# Without the pass statement, having an empty class definition like this 
# would result in an error.
class Person:
  pass

In loops, use the pass keyword as follows:

Example:

gvn_seqnce = {'a', 'b', 'c', 'd'}
for itr in gvn_seqnce:
    pass

Program for pass Statement in Python

Method #1: Using Built-in Functions (Static Input)

In an, if statement, use the pass keyword as follows:

Approach:

  • Give the first number as static input and store it in a variable.
  • Give the second number as static input and store it in another variable.
  • Check if the given second number is greater than the first number using the if conditional statement.
  • If it is true, then give a pass statement.
  • Else print the given first and second numbers.
  • The Exit of the Program.

Below is the implementation:

# Give the first number as static input and store it in a variable.
numb1 = 33
# Give the second number as static input and store it in another variable.
numb2 = 50
# Check if the given second number is greater than the first number using
# the if conditional statement.
if numb2 > numb1:
    # If it is true, then give a pass statement.
    pass
else:
    # Else print the given first and second numbers.
    print(numb1)
    print(numb2)

Output:


Explanation:

Here, We don't get any output as we gave a pass statement if the condition
satisfies.

Method #2: Using Built-in Functions (User Input)

Approach:

  • Give the first number as user input using the int(input()) and store it in a variable.
  • Give the second number as user input using the int(input()) and store it in another variable.
  • Check if the given second number is greater than the first number using the if conditional statement.
  • If it is true, then give a pass statement.
  • Else print the given first and second numbers.
  • The Exit of the Program.

Below is the implementation:

# Give the first number as user input using the int(input()) and store it in a variable.
numb1 = int(input("Enter some random number = "))
# Give the second number as user input using the int(input()) and store it in another variable.
numb2 = int(input("Enter some random number = "))
# Check if the given second number is greater than the first number using
# the if conditional statement.
if numb2 > numb1:
    # If it is true, then give a pass statement.
    pass
else:
    # Else print the given first and second numbers.
    print(numb1)
    print(numb2)

Output:

Enter some random number = 100
Enter some random number = 20
100
20

Find a Comprehensive Collection of Python Built in Functions that you need to be aware of and use them as a part of your program.