Python Function
Package a reusable piece of logic: give it input, let it work, and get a result back.
FUNCTION SYNTAX
Read each colored part
def function_name(parameter1, parameter2):
# statements / process
return result
answer = function_name(value1, value2)
def
Declare function
Declare function
function_name
Function name
Function name
parameters
Input
Input
return
Send result back
Send result back
result
Output value
Output value
function(...)
Call / execute
Call / execute
Mental model: Input ā Function ā Process ā Return ā Use Result
š» Design Your FunctionWrite the function and call it to produce the expected result.
PYTHON CONSOLE
Ready.
š» Design Your FunctionWrite the function and call it to produce the expected result.
PYTHON CONSOLE
Ready.
š» Design Your FunctionWrite the function and call it to produce the expected result.
PYTHON CONSOLE
Ready.
š» Design Your FunctionWrite the function and call it to produce the expected result.
PYTHON CONSOLE
Ready.