Step 1 of 12
Python functions exercises: what you'll practise
In this lesson you practise Python functions with exercises: you define functions, pass them arguments, return values and see which names each function can reach. Every call is drawn as a box, so you can watch the values go in, the work happen and the result come out, instead of guessing.
Here is the whole idea in six lines. Press Play and watch the call add_vat(200, 0.2) open a box of its own, work out the tax inside it, and hand 240.0 back:
In this lesson you'll:
- define a function with
defand call it as many times as you like - pass arguments into parameters, by position and by name, and give parameters default values
- hand a result back with return, and see why
printis not the same - see which names a function can reach (scope), and what happens when one function calls another
- predict what a function does to a list you give it
It takes about 70 minutes. Press Step to run one line at a time, Back to go back, Play to watch it run. In the exercises you pick the missing pieces of real code and press Run tests: the results are what Python 3 really prints for your picks.
Takeaway: a call opens a box, the arguments go into its parameters, and return hands one value back.