KEMBAR78
Returning Data | PPTX
FUNCTION RETURNS
THE RETURN STATEMENT
• Used to end execution of a function
• Can be placed anywhere in a function
• Statements that follow the return statement will not be executed
• Can be used to prevent abnormal termination of an application
• A function can return a value or expression back to the statement that called the
function.
• Ex.
• x = random.random()
• val = math.sqrt(16)
• In a function that returns a value, the return statement can be used to return a value
from the function to the point of call.
• assign it to a variable
• send it to print
• use it in an expression
DECLARING A RETURN FUNCTION
• Code:
Declaring a Basic Function:
def functionName ():
Function Body
return valueToReturn
• Question: What do you believe will happen if write a return
statement with no return value?
• Question: What concept does this remind you of?
CALLING A FUNCTION
• Functions just like variables need to be called in order to be invoked
• Code:
Calling a Function:
functionName ()
o Ex.
val = rtnFnCall()
print(rtnFnCall())
val = rtnFnCall() * 5
FUNCTION WITH RETURN EXAMPLE

Returning Data

  • 1.
  • 2.
    THE RETURN STATEMENT •Used to end execution of a function • Can be placed anywhere in a function • Statements that follow the return statement will not be executed • Can be used to prevent abnormal termination of an application • A function can return a value or expression back to the statement that called the function. • Ex. • x = random.random() • val = math.sqrt(16) • In a function that returns a value, the return statement can be used to return a value from the function to the point of call. • assign it to a variable • send it to print • use it in an expression
  • 3.
    DECLARING A RETURNFUNCTION • Code: Declaring a Basic Function: def functionName (): Function Body return valueToReturn • Question: What do you believe will happen if write a return statement with no return value? • Question: What concept does this remind you of?
  • 4.
    CALLING A FUNCTION •Functions just like variables need to be called in order to be invoked • Code: Calling a Function: functionName () o Ex. val = rtnFnCall() print(rtnFnCall()) val = rtnFnCall() * 5
  • 5.