Functions
LockedLesson 10 of 60 · Syntax · Medium
Finish these first:Loops →Or pass the tests below to unlock it now.
The big idea
Define with def. Support default, keyword, args, and kwargs parameters.
Think of it like this: Think of syntax and expressions like labeled measuring cups in a kitchen: each cup holds a specific kind of ingredient, and operators combine them into a new measurement.
Read the lesson
Define with def. Support default, keyword, *args, and **kwargs parameters. Functions are first-class values.
def power(base, exp=2, *, verbose=False):
return base ** exp
power(3) # 9
power(2, exp=5) # 32
Avoid mutable default arguments (def f(x=[])): the default is created once.
Quick check
Before writing code: What should `append_item(1)` return when your implementation of Functions is working?
Your challenge
Write append_item(x, xs=None) that returns a NEW list with x added, without sharing state between calls.
More learning tools(compare languages, visual guide, related lessons)
Compare with another language
Similar to javascript.functions (88% overlap). Function signatures, return contracts, and lexical vs static scoping.
Visual walkthrough
A diagram, a step-by-step animation, and short captions for Functions.
Learn this first
- LoopsNot yet