Functions · Lesson 11 of 25
Functions with def
Write code once, use it many times.
8 minutes3 games
def defines a function: its name, inputs in ( ), then : and an indented body. return gives back the result. Inputs can have defaults: def greet(name="friend").
Python
def area(width, height):
return width * height
def greet(name="friend"):
return f"Hello, {name}!"
print(area(4, 5))
print(greet("Salma"))
print(greet())Arguments
Function body
Return value
Quick question
What does a function without return give back?
Complete the code
Complete the function that returns double the number.
double(n): n * 2
Exercise
Write is_even(n) returning True for even numbers, then print is_even(10).
Expected output: True
Python
def is_even(n):
Learn more from
Played 0 of 3 games
Sign in to save your progress and earn XP.