Skip to content
beginner to intermediate

Functions and Modules

Learn how to organize reusable Python code with functions, arguments, scope, built-in functions, modules, imports, and practical code-reuse patterns.

Tutorials

Articles in Functions and Modules

Follow these lessons in order, or jump directly to the topic you need.

A breathtaking sunrise over a vast mountainous landscape with clear skies.
beginner
6 min read

Defining Functions in Python

A function turns a block of code into a named tool you can call by name. Write the steps once, give them a name, and reuse them across your program instead…

Read tutorial
Explore summer relaxation with a teal swimsuit covered in sand on a sunny beach.
beginner
7 min read

Importing Modules in Python

An import statement is not a magic incantation. It is a name-resolution request: you tell the running Python program, "find this module and make its names…

Read tutorial
A vivid close-up of a single yellow sow thistle flower in bloom against a dark background.
beginner
14 min read

Practice Exercises: Functions

Reading about functions teaches you the rules. Writing them teaches you the mechanism. These python functions exercises are built so you run code, inspect…

Read tutorial