GCGrowCarrer

Functions

Locked

Lesson 10 of 60 · Syntax · Medium

Finish these first:Loops →Or pass the tests below to unlock it now.

1

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.
Key words (tap to learn):
2

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.

3

Quick check

Before writing code: What should `append_item(1)` return when your implementation of Functions is working?

4

Your challenge

2 sample tests, 1 hidden

Write append_item(x, xs=None) that returns a NEW list with x added, without sharing state between calls.

Stuck? Get a hint (free)
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.

Mastery0%