Module 9: Functions
Learn to write reusable blocks of code that make your programs organized and powerful
Your Progress
Complete the lessons in order, then test yourself with practice problems and the module quiz.
Learning Objectives
By the end of this module, you will be able to:
- Define your own functions using the
defkeyword - Write docstrings to document what your functions do
- Use parameters and arguments to pass data into functions
- Return values from functions using the
returnstatement - Use default values and keyword arguments for flexible function calls
- Understand
*argsand**kwargsfor variable-length arguments - Explain the difference between local and global scope
- Follow best practices for writing clean, reusable functions
Lessons
Defining Functions with def
Learn the syntax for creating your own functions, how to call them, and why functions are essential for writing clean, reusable code.
~35 minutesParameters and Return Values
Pass data into functions with parameters and get results back with the return statement. Learn about positional arguments and returning multiple values.
~35 minutesDefault and Keyword Arguments
Make your functions more flexible with default parameter values, keyword arguments, and an introduction to *args and **kwargs.
~30 minutesScope: Local vs Global
Understand where variables live and die in your programs. Learn about local scope, global scope, the global keyword, and best practices for variable naming.
~30 minutes