Return and Pass Statement

Last updated Aug 10, 2021

Return Statement

The main function of Return Statement in Python is to end the execution of the function and "returns" the result. The statements which come into use after the return statement are not executed. Return Statement in Python is used when you want to execute the program. If the return statement is without any expression (means it does not have anything except return), then a special value i.e. NONE is returned.

Learning the use of Return Statement with the help of an example:-

def func1():
    return 1 + 2
print(func1())
3   

As you can see from the code explained above func1 gives the value of the return statement and provides us the output.

Pass Statement

The Pass Statement is used as a placeholder for the future in a python code. In simple words, we use a pass statement when we want to run a given set of instructions empty means without any arguments. Statements that are empty or do not have any statement are not allowed in loops, function definitions, class definitions, or if statements. For a bigger set of codes, the Pass statement is the best statement that is used in a python program.

Let's understand the use of pass statement with the help of an example:-

for x in [0,1,2]:
    pass
       

From the above code, it is clearly visible that when the pass statement is executed we get no value in the output.

Article Contributed By :
https://www.rrtutors.com/site_assets/profile/assets/img/avataaars.svg

65 Views