functions¶
A function is a unit or block of code that is callable. I can write statements that I can used to do something and call it at different time from when I write it. They can make code smaller and easier to read, test, reuse, maintain and improve.
Programming involves providing a process with input data and the process returning output data
argument -> program -> output_data
I think of it mathematically as mapping a function f
with inputs x
and an output of y
\[f(x) -> y\]
in other words
program(argument) -> output_data
program
is the function that processes argument
to return output_data
functions
are defined using the def keyword, a name, parentheses and a colon at the end
The following tests cover different ways to make a function