Modules can have one or more functions. They help you to organize your code. Instead of one long Python file, you can have several files (modules).

A module is a Python file that has functions or classes. A Python program can use one or more modules.

Related course: Complete Python Bootcamp: Go from zero to hero in Python


We load the os module with the import keyword. Using that module we call one of its functions.

import os

In this case it will simply list the files in the directory (dir command).
To see all functions in a module, start the Python interpreter and type

import os

This will show all functions and classes in the module:

module functions

If you want, you can import a specific function instead of the whole module.

from time import sleep


Try the exercises below

  1. Import the math module and call the sin function

Download answers