Skip to main content

Functions for Pythons

Functions are reusable blocks of code defined with def, taking parameters and returning values. Python supports default and keyword arguments, *args and **kwargs, closures and lambdas. Functional tools such as map, filter, sorted with a key, and decorators let you treat functions as values and pass them around.

Stage: Functions and Modules · Part of the Python roadmap · Last reviewed 19 November 2026

What to learn in Functions

Functions interview questions

Why is a mutable default argument dangerous in Python?

The default value is created once when the function is defined, not on each call. A default like an empty list is shared between calls, so appended items persist. Use None as the default and create the list inside the function.

What does a decorator do in Python?

A decorator is a function that takes another function and returns a new one, usually adding behaviour such as logging, timing or caching. The @name syntax above a definition is shorthand for reassigning the function to the decorated version.

Where Functions fits in the Python roadmap

Functions belongs to the Functions and Modules stage (beginner level), which takes about 28 hours. Organise code.

Back to the full Python roadmap