liveBook · Manning

Positional parameter

As explained in The Well-Grounded Python Developer: How the pros use Python and Flask

A positional parameter is a function parameter whose value is assigned according to its position among the supplied arguments.

A function call is easier to use when its inputs have a clear contract. A positional parameter receives an argument according to where that argument appears in the call. In a function definition, parameters name the inputs; at the call site, arguments supply their values. section 3.1.2

def full_name(fname, mname, lname):
    return f"{fname} {mname} {lname}"

The names in this definition make the expected inputs and their order visible: first name, middle name, then last name. section 3.2.2

Order matters at the call site

Calling full_name("John", "James", "Smith") assigns each string to the corresponding parameter in definition order. Supplying all three by name instead permits a different order, such as full_name(mname="James", lname="Smith", fname="John"). In this definition, omitting a required value raises TypeError. section 3.2.2

Choose the interface to fit the job. Required inputs can be positional; inputs with defaults can be optional keyword parameters. Python’s print function illustrates the combination: it accepts multiple objects to display while offering named settings such as sep and end. Clear input choices make a small function useful without requiring a separate function for every variation. section 3.1.2 section 3.2.2

How The Well-Grounded Python Developer: How the pros use Python and Flask covers it

How deep it goes
Works through definition and call order, named calls, and missing required values without descending into function internals.
Examples
Uses full_name calls with ordered or named arguments and print calls with multiple objects.
What it assumes
Assumes familiarity with Python function calls while distinguishing arguments from parameters explicitly.
What you can do after
Build it from scratch by defining required function inputs in a clear order and calling them accordingly.
How it connects
Connects positional parameters to arguments, keyword parameters, default values, and API design.

Also explained in

Compare how 5 books explain positional parameter →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of The Well-Grounded Python Developer: How the pros use Python and Flask. The section links point to the parts of the book it draws on.