Send data in with positional and keyword arguments, give parameters defaults, and send results out with return — not print.
01
Learning objectives
Distinguish parameters (in the def) from arguments (in the call).
Call functions with positional and keyword arguments, mixed correctly.
Write functions with default parameter values and predict calls that omit them.
Explain the difference between return and print using a function's result.
Trace chained calls where one call's result feeds into another.
02
Lesson notes
Vocabulary first, because the exam tests it: parameters are the placeholder names in the def line; arguments are the actual values written in the call. In def bill(item, qty): and the call bill('pen', 3), item and qty are parameters while 'pen' and 3 are arguments. Positional arguments are matched purely by order: first to first, second to second, third to third.
Keyword arguments skip the order worry: bill(qty=3, item='pen') names each value, so the call reads clearly and cannot be mismatched. You may mix styles — positional first, then keyword — but never a positional argument after a keyword one, which is a SyntaxError. Defaults move flexibility into the definition: def bill(item, qty=1, price=100) lets the call bill('copy') work, filling the omitted parameters with their default values.
return ends the function and hands a value to the caller. That value is then ordinary data: store it, print it, feed it into the next call — double(double(5)) chains naturally. Returning a tuple even delivers two answers at once: return low, high. A function may contain several return statements, one per branch, but each single call executes exactly one of them and then stops.
The return-versus-print distinction is the most failed exam item in this chapter. print writes text to the screen for humans; return gives a value to the rest of the program. A function that only prints computes a result and then throws it away — its caller receives None, so total = printed_version(nums) + 1 crashes with TypeError. The working rule: functions return values; the main code does the printing.
Board tip: when asked for the output of a program, trace arguments into parameters one line at a time, then follow the return value back to the call site. Watch for calls that omit middle arguments (defaults fill them) and for expressions inside calls — f(a + 1, b * 2) evaluates both expressions fully before the function even starts running.
03
Worked code examples
Defaults and keyword arguments
Positional arguments fill item, qty and price in order; a keyword argument skips straight to price; omitted parameters take their defaults, so qty stays 1.