Importing Modules
Learn how to use Python's rich library of modules and build your own.
Importing Modules is a free Learn AI with Python lesson on CoddyKit — lesson 5 of 5. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Learn AI with Python learning path, one of 5 lessons in the course, and your progress syncs across the web and the CoddyKit app.
1
Introduction to Importing Modules
Modules are files containing Python code that can include functions, variables, and classes. By importing modules, you can reuse code and extend Python's functionality.
In this lesson, you’ll learn how to import and use built-in and custom modules.

2
What Are Modules?
A module is a file containing Python code. You can use modules to organize code into reusable pieces. Python comes with built-in modules, and you can create your own as well.
Examples of built-in modules include:
math: Provides mathematical functions.random: Generates random numbers.os: Interacts with the operating system.
3
4
How to Import a Module
You can import a module using the import keyword:
# Importing a module
import math
print(math.sqrt(16)) # Outputs: 4.05
Importing Specific Functions
You can import specific functions or variables from a module:
# Importing specific functions
from math import sqrt
print(sqrt(16)) # Outputs: 4.06
Using Aliases for Modules
You can use aliases to give a module or function a shorter name:
# Using aliases for modules
import math as m
print(m.sqrt(16)) # Outputs: 4.07
Built-in Modules: Examples
Python includes many useful built-in modules:
random: Generates random numbers.datetime: Works with dates and times.os: Provides operating system functionality.
8
Creating Your Own Modules
You can create custom modules by writing Python code in a file with a .py extension. For example:
# Save this code in mymodule.py
def greet(name):
return f"Hello, {name}!"
# Importing the custom module
from mymodule import greet
print(greet("Alice"))9
10
Common Mistakes with Modules
Here are some mistakes to avoid when working with modules:
- Forgetting to install external modules using
pip. - Not using aliases for long module names.
- Overwriting module names with variables (e.g.,
math = 5).
11
What Did We Learn?
In this lesson, you learned:
- How to import built-in and custom modules in Python.
- The difference between full imports, specific imports, and aliases.
- How to create your own custom modules.
Great job! Let’s move to the next topic.

Frequently asked questions
Is the “Importing Modules” lesson free?
Yes — the full text of “Importing Modules” is free to read here on the web, and the Learn AI with Python course includes 5 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Learn AI with Python course, upgrade to CoddyKit PRO.
What will I learn in “Importing Modules”?
Learn how to use Python's rich library of modules and build your own. You practise Learn AI with Python with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Learn AI with Python?
No prior experience is required. Learn AI with Python on CoddyKit is structured for beginners through advanced learners; this is — lesson 5 of 5, so you can start here or from the beginning and move at your own pace.
How long does the “Importing Modules” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Learn AI with Python lesson?
Yes. Every Learn AI with Python lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.