Value Returning Functions

A value-returning function is a function that returns a value back to the part of the program that called it.

A value-returning function is a special type of function.

• It is a group of statements that perform a specific task.

• When you want to execute the function, you call it.

When a value-returning function finishes, it returns a value back to the part of the program that called it.

Syntax:

def fun():

statements

.

.

return [expression]

Example:

# Python program to demonstrate return statement

def add(a, b):

# returning sum of a and b

return a + b

def is_true(a):

# returning boolean of a

return bool(a)

# calling function

res = add(2, 3)

print("Result of add function is {}".format(res))

res = is_true(2<5)

print("\nResult of is_true function is {}".format(res))