loop
How functions communicate with their environment

Module 4 · How functions communicate with their environment · Lesson 2 of 5

Positional parameter passing

The simplest way to pass arguments is the one you've already been using: by position. Python lines the arguments up with the parameters in order — the first argument goes into the first parameter, the second into the second, and so on down the line.

area(3, 4)
position 03
position 14
widthheight
width = 3, height = 4 → area 12

Swap the call to area(4, 3) and now width is 4 — position is the meaning.

It's simple, but it means order carries all the meaning. In area(3, 4), the 3 is the width purely because it came first. Write the values in the wrong order and the function does the wrong thing — without any error to warn you.

Run it yourselfruns in your browser · Python
main.py

That last call is perfectly legal Python and runs happily — it's just nonsense, because the values went into the wrong slots. When a function has several parameters and it's easy to forget the order, there's a clearer way to pass them: by name.