Not sure which lesson to do first? Find your level and get a plan →

CS Thinking · Computational Thinking · Grade 6-8

Parameters

Parameters are the named placeholders declared inside a function definition — the blanks a caller fills in.


Quick Answer

Parameters are the named placeholders declared inside a function definition — the blanks a caller fills in. Use them whenever a function should work on different data each time it runs. When the function is called, each argument is matched to a parameter by position: for def greet(name, times), the call greet('Alice', 2) sets name to 'Alice' and times to 2. Inside the body, parameters behave like ordinary variables holding those values.

Why This Matters

Parameters are what make one function useful in many situations: a single area(w, h) handles every rectangle instead of needing one function per size. Knowing that arguments fill parameters in order lets you predict what a call returns and catch bugs such as passing a height where a width was expected, or leaving out an argument the function needs.

Intuitive Explanation

A parameter is a name written in the brackets of a function's definition: in def area(width, height), width and height are parameters. They have no value yet; they are blanks. An argument is the actual value given in a call: in area(5, 3), 5 and 3 are arguments. When the call runs, the first argument goes into the first parameter and the second into the second, so width = 5 and height = 3, and the body computes 5 * 3 = 15.

Order is the matching rule. For def speed(distance, time): return distance / time, the call speed(100, 20) gives 100 / 20 = 5, but speed(20, 100) gives 20 / 100 = 0.2. The same two numbers produce a different answer because they landed in different parameters. Some languages, such as Python, let you name the arguments, as in speed(time=20, distance=100), which removes the guesswork.

Parameters and arguments are easy to mix up. Parameters belong to the definition and are the same every time; arguments belong to a call and can change from call to call. A parameter also differs from a variable created inside the body: a parameter gets its value from the caller, while a local variable gets its value from a line inside the function.

Think of it like this. Parameters are the blank lines on a printed form, labelled 'Name' and 'Age'. The form is the same for everyone; each person fills in different answers, and the office reads each answer by which line it is on. Write your age on the name line and the office gets it wrong, just as swapped arguments do.

Core idea. Parameters make functions flexible—same code, different data.


When to Use

Use parameters when a question shows a function definition with names in its brackets and a call with values, and asks what each name holds, what the call returns, or why a call gives a wrong answer. Match arguments to parameters by position, or by name if the call uses names. If the question is about what the function sends back, that is Return Values; if it is about defining and reusing the function as a whole, use Function.

Tip. Ask: Is the question about the named slots in a function's definition that get filled by the values in each call?

How to Recognize It

Before naming something a parameter, find where it appears: in the function's definition, or in a call to it.

  1. Does the name appear inside the brackets of the def line?

    Yes means it is a parameter. A value inside the brackets of a call, such as greet('Mia'), is an argument instead.

  2. Do you need to match each value in a call to the right slot?

    Yes means line them up by position: the first argument fills the first parameter, the second fills the second, and so on.

  3. Is the question about what the function hands back when it finishes?

    Yes points to Return Values. Parameters carry data into the function, never back out.

  4. Is the name used anywhere outside the function's body?

    Yes means it is probably an ordinary Variable. A parameter exists only inside its own function, while that call is running.

Parameters vs Argument vs Return Values vs Variable

In a single call like price(item, 3), data flows both in and out, so the names for each part get swapped. Ask where the thing appears: in the definition, in the call, on the way back, or anywhere in the program.

Parameters

Meaning
Parameters are the names listed in a function's definition that receive values when it is called.
Key test
Appears in the definition's brackets, as a name rather than a value.
Formula
f(p1,p2,…,pn)
Example
In def greet(name, times), name and times are parameters.

Argument

Meaning
An argument is the actual value written in a function call, which is copied into the matching parameter.
Key test
Appears in the call, as a real value such as 'Mia' or 3.
Formula
f(a1,a2,…,an)
Example
In greet('Mia', 2), 'Mia' and 2 are the arguments.

Return Values

Meaning
A return value is the result a function sends back out to the code that called it.
Key test
Flows out of the function, after the word return.
Example
def triple(n): return n * 3, so triple(4) sends back 12.

Variable

Meaning
A variable is any named box holding a value, and a parameter is a special variable that lives only inside its function.
Key test
Any named value, often created outside every function.
Example
score = 0 at the top of a program is a variable, not a parameter.

Formula & Notation

Worked Examples

Example 1 — Match arguments to parameters

Easy

def price(cost, qty, discount): return cost * qty - discount. What does price(4, 6, 3) return?
Show the steps and the answer
  1. Match by position: cost = 4, qty = 6, discount = 3.

    The first argument fills the first parameter, the second fills the second, and so on.

  2. Run the body: 4 * 6 - 3.

    Inside the function, each parameter acts like a variable holding its argument.

  3. Compute: 24 - 3 = 21.

    Multiplication happens before subtraction.

Answer: 21

Takeaway: Write down each parameter's value from the call before you run the body.

Example 2 — Order versus names

Standard

def power(base, exp): return base ** exp, where ** means 'to the power of'. What do power(2, 5), power(5, 2), and power(exp=5, base=2) return?
Show the steps and the answer
  1. power(2, 5): base = 2 and exp = 5, so it returns 25=32.

    Positional arguments fill the parameters from left to right.

  2. power(5, 2): base = 5 and exp = 2, so it returns 52=25.

    Swapping the arguments swaps which parameter each value lands in.

  3. power(exp=5, base=2): the names decide, so base = 2 and exp = 5, and it returns 32.

    Keyword arguments are matched by name, so their order in the call does not matter.

Answer: 32, 25, and 32.

Takeaway: Positional arguments are matched by order and keyword arguments by name; the same values in different slots give different results.

Example 3 — Find the mistake: a missing argument

Application

def fence_cost(length, price_per_m): return length * price_per_m. Leila needs 25 m of fence at $8 per metre, and she writes fence_cost(8). Find the mistake and correct it.
Show the steps and the answer
  1. Match the call: fence_cost(8) puts 8 into length, and price_per_m gets nothing.

    Arguments fill parameters in order, so a single value goes to the first parameter.

  2. Spot the two problems: length should be 25, not 8, and price_per_m is missing, so most languages stop with an error.

    Every required parameter needs an argument, and each argument must go in the right slot.

  3. Fix the call: fence_cost(25, 8).

    25 goes into length and 8 into price_per_m, matching the order in the definition.

  4. Trace the fix: 25 * 8 = 200.

    The body multiplies the two parameters.

Answer: Call fence_cost(25, 8); it returns 200, so the fence costs $200.

Takeaway: Give one argument for every required parameter, in the order the definition lists them.

Where You'll See It

  • Filling out a pizza order form

    The form fields (size, toppings, crust) are parameters: blanks you fill in each time so the same 'make a pizza' process works for many different orders.

  • Setting a microwave timer

    The number of seconds you type is an argument for the timer's parameter; the same 'cook' function runs for whatever time you give it.

  • A greeting that uses your name

    A 'say hello' function with a name parameter prints 'Hello, Mia' or 'Hello, Sam' depending on the argument you pass, showing how parameters make one function flexible.

Common Mistakes

  1. The slip: The order you pass arguments doesn't matter as long as you pass the right values.

    Why it's tempting: All the needed values are there, so it feels like the function should sort them out.

    Instead: Arguments fill parameters by position; passing them in the wrong order sends the wrong value to each parameter, even if all values are 'correct.'

  2. The slip: Parameters are the values passed at the call, and arguments are in the definition.

    Why it's tempting: The two terms are easy to swap because they describe the same data slot.

    Instead: Parameters are declared in the function signature (placeholders); arguments are the real values supplied at the call site.

  3. The slip: You can leave out a required parameter and the function still works fine.

    Why it's tempting: The function looks complete, so a missing input seems harmless.

    Instead: Skipping a required argument causes an error or triggers an unexpected default; supply every required parameter when you call the function.


Mini Practice

Try these on your own. Tap Reveal when you want to check.

  1. `def greet(name): return "Hello, " + name`. In the call `greet("Bob")`, which is the parameter and which is the argument? What is returned?

    Hint: One lives in the definition; the other is in the call.

  2. `def power(base, exp): return base ** exp`. What does `power(2, 5)` return? What does `power(5, 2)` return?

    Hint: Arguments fill parameters in order. `**` means "to the power of".

  3. `def price(cost, qty, discount): return cost * qty - discount`. Find `price(4, 3, 2)`.

    Hint: Match each argument to its parameter by position.

  4. `def box(width, height)` is called as `box(height=4, width=3)`. Which value does `width` get? What does `width` get in `box(4, 3)`?

    Hint: Named arguments match by name; plain arguments match by position.

  5. `def double(x): return x * 2` is called with 6. A question asks what comes back to the caller. Is that about the parameter or the return value?

    Hint: Is the question about what goes in or what comes out?

  6. `def subtract(a, b): return a - b`. A student wants 10 minus 3 and writes `subtract(3, 10)`, which gives −7. Fix the call.

    Hint: Which parameter does the first argument fill?

Want the full set?

50 practice questions for this concept — free to try, every one with a complete worked solution showing the why, not just the answer.

Frequently Asked Questions

Can a parameter have a default value?

Yes, in many languages. In Python, def greet(name, greeting='Hello') lets you call greet('Mia'), which uses 'Hello', or greet('Mia', 'Hi'), which replaces it. Parameters with defaults must come after the ones without them in the definition. Defaults are useful when a value is usually the same, so most calls can leave it out.

Can I pass arguments by name instead of by position?

In Python, yes: greet(times=2, name='Mia') sends each value to the parameter with that name, so the order no longer matters. These are often called named arguments. They make long calls easier to read, such as make_box(width=3, height=5, depth=2), where it would be easy to forget which number is which. Java matches arguments by position only.

If I change a parameter inside the function, does the original change too?

For numbers and text, no. With def add_one(n): n = n + 1, calling add_one(score) changes only the function's own copy, so score outside keeps its old value. If you want the new value, end the function with return n and write score = add_one(score). Lists can behave differently in Python and JavaScript, because the function can change the list's contents directly.

How many parameters should a function have?

As many as the job needs and no more. A function with zero parameters, like roll_dice(), can still be useful. Once a function needs five or six, calls become hard to read and easy to get in the wrong order, which is a hint that the function is doing too many jobs or that related values belong together in one group.

Learning Path

← Before

Function
Parameters

You are here

Next →

Return Values
You need Function: a named block of code that runs when it is called. Parameters add the way a call passes data in, so the same function works on different values every time. Next, Return Values covers the other direction, how the function sends its answer back to the line that called it, so the result can be stored or used in a larger calculation.

See Also