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.

Example :

# return statment
def usr_abs (n):
	if n>=0:
		return n
		return –n
# Now invoking the function
x=int (input(“Enter a number :”)
print (usr_abs (x))

Output 1:

Enter a number : 25


Output 2:

Enter a number : -25


CCC Online Test 2021 CCC Practice Test Hindi Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level Online Test in Hindi Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Sarkari Naukari Notification Best Website and Software Company in Allahabad Sarkari Exam Quiz