Return Statement in Python.

Return Statement:

The keyword return is used to return the value after execution of the Statement.

Example:

def max(n1,n2) : if (n1 > n2): return n1 elif (n1 < n2): return n2 else: print("both numbers are equal") print(max(4,6))

Output:

6

Returning Multiple Values:

It is possible to return multiple value in Python.

Example:

def arith(n1, n2): return (n1+n2),(n1-n2) print(arith(23,21))

Output:

(44,2)

Assign Return Multiple Values to Variable:

Example:

def demo(n1): print(n1) return (n1*n1),(n1*n1*n1) square,cube=demo(3) print("square",square,"cube",cube)

Output:

3 square 9 cube 27

Comments

Popular posts from this blog

Introduction to Python.

Decision Making Statement.