SOARDO
Software Engineer (SDE)pythonbeginner3 interactive MCQs in app

Functions, Arguments, Lambda & Scope

mutable default argument trap*args / **kwargs unpackinglocal vs global scope

Functions encapsulate reusable logic with explicit parameters, pure return values, and predictable scope (LEGB rule: Local -> Enclosing -> Global -> Built-in). Always pass mutable defaults carefully: default argument values are evaluated ONCE at `def` time, NEVER on each call! Use `items=None` and initialize `items = [] if items is None else items` inside the body.

`def add_tag(tag, tags=None): tags = [] if tags is None else list(tags); tags.append(tag); return tags` prevents cross-call state leaks.
`def append_item(x, bucket=[])` shares the same list across every caller without arguments.
Defining Python Functions — Real Pythonread ↗Functions, Arguments, Lambda & Scope — Applied Practicepractice ↗Exercism Python Track (Interactive)practice ↗

Practice Functions, Arguments, Lambda & Scope with 3 graded MCQs & written feedback.

Take SOARDO’s free 12-question diagnostic to see how strong you are across your target role and unlock adaptive daily missions.

Test yourself free on SOARDO →View full Software Engineer roadmap

More Software Engineer Study Guides