Python return statement

Python Methods and Functions

Note. The return statement cannot be used outside of a function.

Syntax :

 def fun (): statements. ... return [expression] 

Example :

# Python program for
# demonstrate refund

 

def add (a, b):

 

# return the amount a and b

return a + b

 

def is_true (a):

  

  # returning a boolean  

return bool (a)

 
# calling function

res = add ( 2 , 3 )

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

 

res = is_true ( 2 & lt; 5 )

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

Exit :

 Result of add function is 5 Result of is_true function is True 




Get Solution for free from DataCamp guru