← Python

Functions – Default Arguments

A default argument provides a fallback value used when the caller omits that argument

What it does: If no argument is passed, name uses its default value 'World'. power(3) uses exp=2 by default. power(3, 3) overrides to exp=3. 'Alice' overrides the default — name becomes 'Alice'. Required parameters must come first — defaults follow them. No exp given — exp defaults to 2. 3**2 = 9. 3 overrides the default — 2**3 = 8. All parameters can have defaults — calling the function with no args then uses all defaults. Only a has no default — b and c are optional.

Common mistakes: Default parameters must come AFTER required ones. Default value 'World' needs quotes: it's a string.

Class: _____________________  ·  Name: _____________________  ·  Date: _________

Free printable worksheet with full answer key — or add this module to a journey and assign it to your class.

Take this worksheet further — free with Cloodit

Each concept is reinforced from every angle — learned, then applied, then tested.

Learning
Duo
What is a default argument?
A pre-set value used when no argument is givenThe first argument
Matches
❌ def greet(greeting='Hi', name): pass
Error: Default args must come last
Applying
Meanings
Term
Default argument
Meaning
A pre-set value used when no argument is provided.
Practice
def greet(name='World'):
Testing
Gaps
def greet(name=):
Check Answer
Spots
1def greet(name='World', msg):
2 full = msg + ' ' + name

Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.

The 'Cheetah' badge — Savannah Sprinter, one of Cloodit's 106 collectible badges
Students earn collectable badges

Over 100 of them, across seven natural biomes.

Study Buddy
Students build a real study resource

Turns their work into revision material ready for Flash Cards and Exam study.

Diamond Dash — one of Cloodit's live, competitive Sprint games
Students lock in with Sprints

Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.

A Cloodit certificate of achievement, ready to personalise and print
Custom printable certificates

Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.

Quick Questions

1. What is a default argument?
A. A pre-set value used when no argument is given ✓
B. The first argument
Default arguments let callers skip a parameter — Python uses the preset value
2. def greet(name='World'):\n print('Hi ' + name)\ngreet()\nWhat prints?
A. Hi name
B. Hi World ✓
No argument given — name defaults to 'World'
3. def greet(name='World'):\n print('Hi ' + name)\ngreet('Alice')\nWhat prints?
A. Hi Alice ✓
B. Hi World
'Alice' overrides the default — name becomes 'Alice'
4. Where must default parameters go?
A. Before required parameters
B. After all required parameters ✓
Required parameters must come first — defaults follow them
5. def power(base, exp=2):\n return base ** exp\npower(3)\nWhat returns?
A. 9 ✓
B. 6
No exp given — exp defaults to 2. 3**2 = 9

Match the Pairs

def greet(greeting='Hi', name): pass Error: Default args must come last
def power(base, exp=2): return base ** exp power(exp=3) Error: Missing required 'base'
def greet(name='World'): print('Hi ' + name) Valid: name is optional
def power(n, exp=2): return n ** exp Ok: exp defaults to 2
def hi(name='World'): print('Hi', name) hi() Output: Hi World
def hi(name='World'): print('Hi', name) hi('Alice') Output: Hi Alice

Key Term

Default argument
A pre-set value used when no argument is provided.~~Optional parameter

Fill in the Blanks

1. def greet(name='World'): print('Hi ' + name)
2. def power(base, exp=2): return base ** exp
3. def repeat(msg, times=3): for i in range(times): print(msg)
4. def greet(name='World'): print('Hi ' + name) greet('Alice')
5. def func(a, b=5, c=10): return a + b + c

Spot the Error

Question 1
A def greet(name='World', msg):
B full = msg + ' ' + name
C print(full)
D return full
E greet('Hi')
Line A — Default parameters must come AFTER required ones
Question 2
A def greet(name=World):
B msg = 'Hi ' + name
C print(msg)
D return msg
E greet()
Line A — Default value 'World' needs quotes: it's a string
Question 3
A def power(base, exp: 2):
B result = base ** exp
C print('Result:', result)
D return result
E power(3)
Line A — Use = for default values, not : (colon is for type hints)
Question 4
A def greet(name = 'World'):
B msg = 'Hi ' + name
C print(msg)
D return msg
E greet()
Line A — Convention: no spaces around = in default parameters (PEP 8 style)
Question 5
A def repeat(msg, times=3):
B for i in range(times):
C print(msg)
D
E repeat(times=2)
Line E — msg is required: you must provide it even when using keyword arguments
For Teachers

Create a free class, add this module to a journey, and track who's stuck.

Create a free teacher account →

No credit card. No setup fee. Make a class and invite students in under three minutes.

For Students

Practice this topic interactively, track progress, and unlock badges.

Start Learning Free →

Have a class code?