1. Concept library
  2. Python Foundations
  3. Module 3: Functions

Concept

Default and keyword arguments

Parameters can carry default values, and callers can pass arguments by name. Together they make functions flexible without a pile of overloads.

What a session covers

The tutor works through these with you, in conversation and code. A session ends when you have shown them, not when a video does.

  1. Explain how default values and keyword arguments make one function serve several cases
  2. Call a function with positional, keyword and default arguments and predict what each receives
  3. Spot the shared mutable default and rewrite it with None

In practice

A few lines that show Default and keyword arguments doing its job.

Python
def connect(host, port=5432, timeout=10):
    return f"{host}:{port} ({timeout}s)"

print(connect("db.local"))
print(connect("db.local", timeout=3))
print(connect(port=6543, host="other"))

The common mistake

Watch for

Using a mutable default such as items=[]. The list is created once, when the function is defined, so every call that relies on the default shares and mutates it. Default to None and create the list inside.

What to know first

Your roadmap puts these before Default and keyword arguments, unless you already know them.

How it stays learned

Once a session shows you understand Default and keyword arguments, it comes back for review. Each review takes a minute and tells the memory model how well you still know it.

  1. Day 3First recall, while it is fresh
  2. Day 7Second, a week on
  3. Day 18Last, when it has settled
Previous in the module← Parameters and return values
Next in the moduleScope →