Skip to content
Python and Data Primer / Python Foundations

Functions

A return calculation is easier to check when its inputs and output are explicit. A Python function gives the calculation that boundary. This lesson defines parameters, return values and local names, then combines small calculations. The same structure supports testing and reusable scripts.
Learning objectives. By the end of this note you should be able to:
  • define and call a function;
  • distinguish a parameter from an argument;
  • return a value rather than print it inside the calculation;
  • state a simple input–output contract.

In this lesson

  1. Turn a formula into a reusable calculation
  2. Local scope contains intermediate names
  3. Compose small functions
  4. Separate calculation from display

Before you start

This lesson is part of a free topic. Create a free account, no card needed, to read it in full with worked examples and exercise solutions.

Read it free