CodeAgeBy Sitezack
Chapter progress0/3

Lesson 1 of 3

Defining functions with def

A function encapsulates a reusable block: def name(parameters): followed by an indented body. return sends a value back to the caller.

Keep return (produces a value) distinct from print (only displays): a function that prints without return returns None.

def double(x):
    return x * 2

print(double(21))

🎯 Exercise

Define a function greet(name) that returns the string Hello, {name}! (using an f-string), then print greet("Ada").

PRO lesson

This advanced chapter is part of CodeAge PRO. Unlock it to keep your adventure going.

Discover PRO