| return value | the value, in place of the call | a value to store or use |
| Example: box_volume(20, 15, 10) is worth 3000; v = box_volume(20, 15, 10) keeps it. |
| n = n + 1 on a number parameter | nothing | the caller's variable unchanged |
| Example: x = 4, then add_one(x) with n = n + 1 in its body: x still holds 4. |
| t[i] = ... on an array parameter | the change of the cells | the caller's array changed |
| Example: scores = [12, 9, 15], then add_bonus(scores) adds 5 to each cell: scores holds [17, 14, 20]. |
| t = [...] on an array parameter | nothing | the caller's array unchanged |
| Example: t = [0, 0, 0] in the body leaves scores as it was; the new array is lost at the return. |
| reading a global name | nothing | allowed, nothing changes |
| Example: With bonus = 5 outside, return p + bonus gives 17 for p = 12. |
| print(value), no return | text on the screen | None no value given back |
| Example: def area(w, h): print(w * h) displays 12 for area(3, 4), and area(3, 4) + 2 stops with a TypeError. What to do: Write return w * h in the function, and print at the call if a display is wanted: print(area(3, 4)). |
| level = level + 1 on a global name | an UnboundLocalError | the program stops run-time error |
| Example: level = 1 outside, then level_up() with level = level + 1 in its body: the call stops before any change. What to do: Pass the value and give the new one back: def level_up(level): return level + 1, then level = level_up(level). |