Mark As Completed Discussion

One Pager Cheat Sheet

  • We will learn about functions, their parameters and working statements to create modular and reusable code blocks.
  • Functions enclose a set of statements to make 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 def keyword followed by the function name, parenthesis (with function parameters, if any), a colon, and an indented body.
  • We can make a function work in our program by calling it with its name, followed by parentheses ( ).
  • It is not possible to call a function before it has been defined and implemented with all its statements and parameters established.
  • 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 parameters that can be specified, provided they are separated correctly and referenced correctly within the function.
  • A return statement in a function can allow the function to pass back a return value to the variable that called it.
  • The variable result is set to None implicitly returned by the div() function, resulting in None being printed when printing the value of result.
  • The variable result contains 4, the larger value returned by the function compare_num(), which compares a (4) and b (2) and prints out "a is greater than b" when a is the greater value.
  • With functions, we can reuse and organize code more efficiently, avoiding the mistake of forgetting to call them.