Functions · Lesson 40 of 76
Defining functions
A function is a reusable block of code with a name. Define it with def, then call it:
Python
Functions keep your program tidy: write the logic once, use it anywhere.
Your turn: write area(width, height) that returns width * height, then print area(4, 5).
Check your understanding
Exercise — check your understanding
Write a function area(width, height) that returns width times height.
You’re reading for free. Sign in to keep your progress and earn a certificate when you finish.Sign in to keep my progress →