One Pager Cheat Sheet
- We will learn about functions, their
parametersand working statements to create modular and reusable code blocks. - Functions
enclose a set of statementstomake it easier to organize and reuse code, following a specific structure. - We will learn to create and use our own user-defined functions in our program, as well as review existing built-in functions.
- Creating functions in Python requires a
defkeyword followed by the function name,parenthesis(withfunction parameters, if any), a colon, and an indentedbody. - We can make a function work in our program by
callingit with itsname, followed by parentheses( ). - It is not possible to call a function before it has been defined and implemented with all its
statementsandparametersestablished. - Functions can take in external information through function parameters specified inside the parenthesis after the function name, which is then passed to the function call when invoked.
- There is no upper limit to the number of
function parametersthat can be specified, provided they are separated correctly and referenced correctly within the function. - A
returnstatement in a function can allow the function to pass back areturn valueto the variable that called it. - The variable
resultis set toNoneimplicitly returned by thediv()function, resulting inNonebeing printed when printing the value ofresult. - The variable
resultcontains4, the larger value returned by the functioncompare_num(), which comparesa(4) andb(2) and prints out "a is greater than b" whenais the greater value. - With
functions, we canreuse and organizecode more efficiently, avoiding the mistake of forgetting to call them.



