You’ll be able to
- Define functions with
defand return values withreturn - Pass positional and keyword arguments
- Set default parameter values
- Understand variable scope: local vs global
Loading lesson…
Why this matters
Functions are the unit of reuse and testing in every Python codebase. Frameworks like Flask, FastAPI, and pytest are built on decorated functions, and knowing default-argument traps is a common senior-level interview question.
Common pitfalls
- Using mutable defaults:
def f(x=[]). The list persists across calls; usex=Nonethenx = x or []inside. - Forgetting
return. A function without it returnsNone, silently breaking any caller that expected data. - Mixing positional and keyword args wrong:
f(a=1, 2)raisesSyntaxError. Positional must come before keyword.