Python return statement

A function represents a group of statements to perform a task. The purpose of a function is to perform some task and in many cases a function returns the result. A function starts with the keyword def that represents the definition of the function. After 'def' , the function should be written. Then we should write variables in the parentheses. For example,

return examples

CopiedCopy Code

def sum(a, b): 
   function body

A function is executed only when it is called. At the time of calling the sum() function, we should pass values to variables a and b. So, we can call this function as:

CopiedCopy Code

sum(3,4)

A function to find the sum of two numbers.:

CopiedCopy Code

def sum(a, b): 
	return (a+b) 
A = sum(5, 10) 
B = sum(1.5, 2.5)