Keyword arguments
You can pass any argument by name: resize(img, width=100, height=50). Named
arguments can come in any order, and they make calls readable when there are
several numbers or booleans.
Two markers in the parameter list control how callers may pass things:
- Parameters after a bare
*are keyword-only.def sort(items, *, reverse=False)forcessort(x, reverse=True). Nobody can write a mysterioussort(x, True). - Parameters before a
/are positional-only. Callers can't use their names, so you can rename them later without breaking anyone.
Built-ins use both: sorted(iterable, /, *, key=None, reverse=False). That is
why sorted(nums, True) is an error.
Interviewers rarely ask about /, but keyword-only flags show good API sense.
Run it, then try connect("db", 5432, 3.0) to see the TypeError.