Lesson 14 of 55
15 mins readPython Optional, Default, and Rest Parameters
In Plain English
Learn how to mark parameters as optional (?), provide compile-time default initializers, and capture variable arguments using typed rest parameters.
Core Rules to Remember

Optional Parameters: Marked with ?, must appear after all required parameters.

Rest Tuples: Collects variable arguments into a strongly typed array or tuple.
Live Interactive Example
Hit Run Code to see it liveFlexible Function Arity
Python 3.12
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
Output Console
Click "Run Code" to view the rendered output.
How it works: channel defaults to email when omitted; urgency is optional; rest numbers collect arguments.
Your Turn: Micro Challenge
No pressure! Edit the starter code below and test your solution with instant feedback.
Micro Exercise
Build a Log Formatter with Rest Tags
Create a function formatLog(message: string, level: string = "INFO", ...tags: string[]): string.
Format and return: `[${level}] ${message} | Tags: ${tags.join(", ")}`.
Call formatLog("DB connected", "READY", "db", "auth") and print the result.
1
2
3
4
5
Sandbox Output
Click "Run & Check" to test your solution.
Finished reading and practicing?
Mark this lesson as completed to update your course progress.