Chapter 5

Functions

functionsparametersreturn valuesdocstringsscope

Learning Path

Hands-on Labs

Each objective has a coding lab that opens in VS Code in your browser

Objective 1

Define and call functions

Goal

You will create reusable code blocks with functions. Write a greet function, call functions multiple times with different arguments, and understand the execution flow when functions are called.

Objective 2

Use parameters

Goal

You will make functions flexible with parameters. Add single parameters, use multiple parameters, and set default values for optional parameters.

Objective 3

Return values

Goal

You will return data from functions. Return single values, return multiple values as tuples, and use return in conditional branches for different outcomes.

Objective 4

Document with docstrings

Goal

You will document your functions with docstrings. Write basic docstrings describing function purpose, document parameters with their types and meanings, and document return values.

Objective 5

Understand scope

Goal

You will understand variable scope in Python. Recognize local variables inside functions, understand when to use the global keyword, and avoid common scope-related bugs.