Starlit Daily

📚 › Python: the friendliest first language

10. Functions

Define a function with def, a name and parameters. return sends a value back. Calling a function means writing its name with brackets.

Functions keep programs tidy: name a job once, reuse it everywhere.

Show example

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

print(greet("Karim"))

✍️ Your turn

Write square(n) that returns n times n, then print square(9).

← Back to course