The return Statement
·
The return statement causes your function to exit and returns a
value to its caller. The point of functions in general is to take inputs and
return something.
·
The return statement is used when a function is ready to return a
value to its caller. So, only one return statement is executed at run time even
though the function contains multiple return statements.
·
Any number of 'return' statements are allowed in a function
definition but only one of them is executed at run time.
return [expression
list ]
This statement can contain expression which
gets evaluated and the value is returned. If there is no expression in the
statement or the return statement itself is not present inside a function, then
the function will return the None object.
Example :
#return statment
def usr_abs(n):
if n>=0:
return n
else:
return –n
#Now invoking the function
x=int (input(“Enter a number :”)
print (usr_abs (x))
Output 1:
Enter a number : 25
25
Output 2:
Enter a number : -25
25
Related Topics
Privacy Policy, Terms and Conditions, DMCA Policy and Compliant
Copyright © 2018-2023 BrainKart.com; All Rights Reserved. Developed by Therithal info, Chennai.