Blue Hat – Functions & Modules
intermediate25 XP

Functions

Create reusable blocks of code with parameters and return values

Functions

Python
def greet(name):
    print(f"Hello, {name}!")

greet("Alex")    # Hello, Alex!
greet("Jordan")  # Hello, Jordan!

Return Values

Python
def add(a, b):
    return a + b

result = add(5, 3)
print(result)  # 8

Lambda

Python
double = lambda x: x * 2
evens = list(filter(lambda n: n % 2 == 0, [1,2,3,4,5,6]))
⌨️

Type it yourself

Don't just read it — type the example from above into the box, press Run ▶, and watch what happens. Typing it yourself is how it really sticks! Stuck? Tap Show example.

Python · Playground
Output
Press ▶ Run to see your code come to life…

Quick check

01/2

What keyword defines a function in Python?