What are the four parts every function needs — and why does defining one run no code at all until you actually call it?
Short drills on what this video just taught. Write the code, run the checks, and reveal the answer only if you are stuck.
Define a function named square that takes one number n and gives back that number multiplied by itself. You don't have to call it — the checks call square with several inputs for you.
Built-in functions and their inputs and outputs
List max, abs and len with what each takes in and gives back, and record the words function and procedure for such named pieces of code.
The docstring as a contract
Write the three points a specification must state — the inputs, what the function does, what it gives back — and note that Python leaves the contract unenforced.
Defining a function versus running it
State that a definition only tells Python the function exists and executes none of its lines, and that one definition supports many later calls with different inputs.
The four parts of a function
Name them in order — a name, zero or more parameters, a docstring, and a body that hands back a value with return — with a line on each.