Parameters

intermediate20 min

Learning objectives

  • Explain the purpose of parameters
  • Distinguish between parameters and arguments
  • Design reusable parameterised functions
  • Implement functions using multiple parameters

Learn

AQA 4.1.1.11 — Parameters and parameter interfaces

Retrieval: the previous lesson's functions, like square(n), already had a parameter (n) without it being named as such - this lesson gives that mechanism its proper terminology and shows how to use more than one.

A parameter is a named placeholder in a function's definition; an argument is the actual value passed in when the function is called. This distinction is a genuine, common exam point — get the terminology precise.

def calculate_grade(score, pass_mark):   # score, pass_mark = parameters
    if score >= pass_mark:
        return "Pass"
    return "Fail"

result = calculate_grade(72, 40)          # 72, 40 = arguments

Multiple parameters, and default values

def calculate_total(price, quantity, discount=0):
    return price * quantity * (1 - discount)

calculate_total(9.99, 3)          # discount defaults to 0
calculate_total(9.99, 3, 0.1)     # 10% off

Worked example — a student grading system

def grade_student(name, score):
    if score >= 90:
        grade = "A*"
    elif score >= 80:
        grade = "A"
    elif score >= 70:
        grade = "B"
    else:
        grade = "C or below"
    print(f"{name}: {grade}")

grade_student("Aisha", 92)
grade_student("Tom", 76)

Because grade_student is parameterised, it works for any name and score — that's the whole point of using parameters rather than hard-coding values inside the function.

Reflection

Why is def grade_student(name, score): more reusable than a version that hard-codes name = "Aisha" inside the function body?

Practise

Apply what you've just learned in the Coding Lab.

Open Coding Lab
Log in to track this lesson on your progress dashboard.
Log in