def
return
f(x)
scope
recurse
params
call()
base case
Unit 5 of 5 — Final Unit

Abstraction

Functions let you name a piece of logic and reuse it forever. Recursion lets functions call themselves. Together, they're how real software is built.

6
Lessons
24
Challenges
1
Project
What You'll Learn

Skills Unlocked in This Unit

Define Functions

Package logic into reusable def blocks with docstrings.

📥

Parameters & Returns

Pass data in and get results back — the function contract.

🔒

Understand Scope

Local vs global, why variables inside functions stay inside.

📦

Process Collections

Write functions that take lists/dicts and return results.

🔄

Think Recursively

Functions that call themselves — base case + recursive case.

🧰

Build a Toolbox

Assemble a reusable utility module — your final project.

Anatomy

Inside a Python Function

Hover over each line to see its role.

🔬 Function Anatomy

Reference
def calculate_area(width, height):definition
"""Return the area of a rectangle."""docstring
area = width * heightbody
return areareturn value
result = calculate_area(5, 3)function call
print(result) # 15
Lesson Roadmap

Your Path Through Unit 5

6 lessons — the biggest unit yet! Click any to see challenges.

5.1 Defining & Calling Functions

4 challenges

Write your first functions with def, understand return vs print(), and DRY.

defreturnDRYdocstrings
Challenges
Greeting Machine
Area Calculator
Temperature Tools
Refactor
Start Lesson →
📥

5.2 Parameters & Return Values

4 challenges

Default values, multiple returns with tuples, and None.

defaultstuplesNone
Challenges
Power Function
Min and Max
Validation Function
Flexible Greeting
Start Lesson →
🔒

5.3 Scope & Variable Lifetime

4 challenges

Local vs global, shadowing, and the LEGB rule.

localglobalLEGB
Challenges
Scope Detective
Counter Function
Bug Hunt
Encapsulation
Start Lesson →
📦

5.4 Functions + Collections

4 challenges

Pass lists and dicts to functions, return collections, build a toolkit.

list paramsdict paramstoolkit
Challenges
Stats Toolkit
Filter Function
Merge Contacts
Mini Gradebook
Start Lesson →
🔄

5.5 Introduction to Recursion

4 challenges

Base cases, recursive cases, call stack, and factorial.

base caserecursive casecall stack
Challenges
Countdown (Recursive)
Factorial
Sum of List
Fibonacci
Start Lesson →
🧩

5.6 Recursion in Practice

4 challenges

Recursive strings, palindromes, call trees, and list flattening.

string recursionpalindromeflatten
Challenges
Reverse String
Palindrome Checker
Power (Recursive)
Flatten
Start Lesson →
🏗

Final Project Mini Python Toolbox

capstone

Build a utility module: 8+ functions including list processing, dict processing, and recursion.

functionsparamsreturnrecursiondocstrings
Requirements
8+ functions with docstrings
At least one recursive
At least one list processor
At least one dict processor
Start Project →

The Final Chapter

Functions are the most important concept in programming. Let's master them.

Begin Lesson 5.1 →
Prerequisite: Unit 4 (Collections)