Starlit Daily

📚 › Python: the friendliest first language

10. Functions

Este artículo se traducirá automáticamente. Por ahora se muestra en inglés.

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.

Ver ejemplo

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

print(greet("Karim"))

✍️ Ahora te toca

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

← Volver al curso