the Return statement
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.
Syntax of return
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.
# 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))
Enter a number : 25
Enter a number : -25