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.

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

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.

Study drill

Try the exercises below