Home | | Computer Science 12th Std | The return Statement

Python - The return Statement | 12th Computer Science : Chapter 7 : Core Python : Python Functions

Chapter: 12th Computer Science : Chapter 7 : Core Python : Python Functions

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

·        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

else:

return –n

#Now invoking the function

x=int (input(“Enter a number :”)

print (usr_abs (x))

Output 1:

Enter a number : 25

25

Output 2:

Enter a number : -25

25

 

Tags : Python , 12th Computer Science : Chapter 7 : Core Python : Python Functions
Study Material, Lecturing Notes, Assignment, Reference, Wiki description explanation, brief detail
12th Computer Science : Chapter 7 : Core Python : Python Functions : The return Statement | Python


Privacy Policy, Terms and Conditions, DMCA Policy and Compliant

Copyright © 2018-2024 BrainKart.com; All Rights Reserved. Developed by Therithal info, Chennai.