Parameters and arguments
A function that always prints the same message is useful, but a function that can greet any name is more reusable. Parameters describe what a function needs; arguments supply the values for a particular call.
The parameter belongs to the definition
In def greet(name):, name is a parameter: a local name that receives a value when the function is called. In greet("Maya"), "Maya" is the argument supplied to that parameter.
Choose names that tell the reader what each input means. If you ask for price and quantity, calling the function should be easier to understand than passing unexplained numbers to names like a and b.
Positional and keyword calls
For a positional call, Python matches supplied values to parameters by their order. A keyword call explicitly names the parameter: label(text="Ready", prefix="Status"). Keywords can clarify long argument lists.
Python prevents many ambiguous calls, for example supplying the same parameter both positionally and by keyword. Read the exception rather than guessing which value was used.
Defaults make optional inputs practical
A parameter can have a default value: def show(name, suffix="!"). The caller may omit that argument, or supply a different value. Place parameters without defaults before parameters with defaults.
Default values are evaluated when the function definition executes, not every time the function is called. Avoid using a shared mutable list or dictionary as a default unless sharing state is deliberate; that pitfall deserves explicit attention later.
Design predictable interfaces
A function that needs ten unrelated arguments is hard to use. Prefer a focused function with a few clearly named inputs. Where information may be missing, decide whether a default is genuinely appropriate or whether validation should reject the call.
Good parameters describe data, not how the user happened to collect it. We can pass a string entered in a form, a value from a file, or a literal; the function should behave consistently for the same valid inputs.
Try it yourself.
Choose a starting example or write something completely different. You control the code; the Run button executes what is in the editor, not a hidden preset.
Change the argument without rewriting the function.
Press Run Python to execute the editable code.
Add a third call for your own name. Which line changes?
Need a hint?
The function definition stays untouched; only the argument differs.
On first Run, a pinned Python runtime downloads from jsDelivr. Code executes locally in your browser's Web Worker, not on our server. It cannot inspect your normal PC files or Windows hardware. Avoid entering secrets. Heavy/infinite loops are stopped by a time limit.
Check your understanding.
Try answering each question before opening its reference answer. Explain the idea aloud or change an example to test it for yourself.
What is the difference between a parameter and an argument in a function call?
View answer
A parameter is the named input declared by the function, such as
nameindef greet(name):. An argument is a value supplied at a call site, such as"Sam"ingreet("Sam"). During that call, the parameter name refers to the supplied value inside the function body; a different call may supply another value.How do keyword arguments and defaults help callers, and what risk comes with a mutable default value?
View answer
A keyword call, for example
greet(name="Sam"), shows which parameter receives each value. A default such aspunctuation="!"makes an input optional. Be careful with a default list or dictionary: Python creates the default once when defining the function, so changes to that object can persist across calls unexpectedly. For new mutable collections, prefer an explicitNonedefault and create the collection inside the function.
Where this leads.
Parameters bring information in. Return values let a function give a useful result back to the code that called it.