Python Optional Positional Parameters & Default Values
While named parameters use curly braces `{ }`, Optional Positional parameters are wrapped in square brackets `[ ]`. Callers do not label them by name; instead, they are supplied in strict positional order. Optional positional parameters can have default values or be nullable.
"Optional positional parameters are like ordering a combo meal: you must order the burger first, then you can optionally choose fries, and optionally a drink in that exact order."
Deep Dive: How It Works
Positional Sequence: Callers cannot skip the first optional positional argument to supply the second one.
Mutual Exclusivity: A function signature can have named parameters OR optional positional parameters, but NEVER both.
Defaults: `[String prefix = "INFO", int indent = 0]` assigns fallback constants when omitted.
Syntax Blueprint
String log(String message, [String level = "INFO", int code = 0]) {
return "[$level:$code] $message";
}Positional arguments followed by bracketed optional positional parameters.
Core Rules to Remember



Common Beginner Traps & How to Fix Them
Trying to mix `{ }` named parameters and `[ ]` optional positional parameters in the same function signature.Why it happens: Dart syntax disallows combining both styles in a single parameter list.
How to fix: Standardize on named parameters `{ }` for functions with more than 2 optional arguments.
Live Interactive Example
Hit Run Code to see it liveYour Turn: Micro Challenge
No pressure! Edit the starter code below and test your solution with instant feedback.
Create Function with Optional Positional Arguments
Define `String wrap(String text, [String tag = "div"]) => "<$tag>$text</$tag>";`.
Inside `main()`, print `wrap("Header", "h1")` and `wrap("Content")`.
Finished reading and practicing?
Mark this lesson as completed to update your course progress.