Functions
4. Functions#
In Chapter 2, we printed a lot of variables and their types. For each of these ‘jobs’ we had to write the print statement explicitly. Likewise, in Chapter 3, there were many repeating code blocks. The result: we wrote many copy-pasted statements that look almost the same. Copy-pasting redundant code is not a good practice, as creates more work for you and will lead to programs that grow to be really large. That is when functions come to help. Functions are code blocks that only run when they are called. They help avoid code repetition by defining functions that can be called separately (and multiple times when needed).
Chapter Summary
What are functions?
Functions with default values
Functions with an arbitrary number of arguments
Scope of a variable
Importing modules
Methods (Optional)