Skip to content

Functions

What you'll learn

  • Function definition and return values
  • Positional and keyword arguments
  • Scope basics

Explanation

Functions group behavior into reusable units. Prefer small, explicit functions with clear names and predictable return values.

Example

Run it in the browser:

def area(width: float, height: float) -> float:
    return width * height

print(area(3.0, 4.0))

Common mistakes

  • Mutating arguments unexpectedly
  • Using mutable default values

Exercises

See Foundations Exercises.

Further reading