Lesson 15 of 16 · 50 min · UG / professional
Arguments, defaults and house style
Order is easy to swap. Put meaning in names; keep GST in CONFIG (the sandbox twin of a default argument). Four-space indent and one quote style are how a file survives 1 a.m.
Library desk
A fee function you can test.
You will be able to
- ✓ Pass arguments in an auditable order
- ✓ Keep defaults in CONFIG (sandbox twin of default args)
- ✓ Keep house style consistent
Order, keywords, defaults
add_gst(amount, rate) is readable. add_gst(18, 200) looks like 200 percent GST. On a laptop, add_gst(amount=200, rate=18) names the holes. def add_gst(amount, rate=18) is a default — evaluated once at def time, which is why a default list is a trap (later lesson). Here CONFIG["gst"] is the searchable default.
*args and **kwargs collect extra positional and keyword arguments on a laptop. Keyword-only arguments after * exist in Python 3. You still design as if names travel with values.
House style
Four spaces, one quote style, names after meaning (late_fee, not x). That is the spirit of the usual style guide — not fashion. The next intern reads this file after an incident.
Words that matter
- Positional argument
- Matched by order — easy to swap.
- Default
- Used when the caller omits an argument — CONFIG here.
- House style
- Agreed quotes, indents and names.
Common mistakes
Avoid: add_gst(18, 200) because you remembered the order that morning.
Do this: Names in the call on a laptop, or CONFIG you pass here.
Run it step by step
Each box is a real program. Press Run, change a number, Run again — the output must follow your code.
1. Step 1 — amount then rate
Print both so a clerk can audit.
Edit the example, press Run, then Build if you want a compile check.
build
Press Build to compile.
2. Step 2 — default as config
Tests can pass 0.
Edit the example, press Run, then Build if you want a compile check.
build
Press Build to compile.
Example program — One style, two callers
Same quotes, same names.
Edit the example, press Run, then Build if you want a compile check.
build
Press Build to compile.
Your turn — Named rate from config
CONFIG gst is 18. Print add_gst(50, CONFIG["gst"]) so 59 appears.
Edit the example, press Run, then Build if you want a compile check.
build
Press Build to compile.
Self-assessment
Check your understanding before you mark the lesson complete.
Progress is stored in a browser cookie on this device.