Lesson 9: Functions

⏱ ~20 min Lesson 9 of 10 💚 Free

A function is a named block of code you can run any time by calling its name. Functions let you write code once and use it many times — one of the most important ideas in all of programming.

Key Concepts

Defining a Function

def greet(name): defines a function called greet. Everything indented below it is part of the function. It does not run yet — it just gets defined.

Parameters and Arguments

Parameters are the variables listed inside the parentheses in def. Arguments are the actual values you pass when you call the function. def add(a, b) has two parameters.

Return Values

return sends a value back to whoever called the function. total = add(3, 4) stores the returned value. Functions without return send back None.

🆕 Try It: Live Python

Try it — edit the code and click Run!

✅ Check Your Understanding

1. What keyword starts a function definition?

2. What does return do?

3. Can you call a function more than once?