Search⌘ K
AI Features

Modules and Packages

Python facilitates code reusability through modules, which are essentially Python files imported into other files. The language features a vast Standard Library with built-in modules like math, csv, sys, and os for various functionalities. Packages, composed of one or more modules, are structured within directories and include an __init__.py file. This allows for organized distribution of larger codebases, with numerous useful packages available from the Python Package Index for diverse applications such as machine learning and web development.

We'll cover the following...

Python modules

Most languages allow reusable chunks of code to be bundled up and made available to other code. Python supports this through modules.

In Python, a module is simply a Python file imported into another Python file. For example, if we create a file called mymodule.py and add a test function:

Python 3.5
def test():
print('test')

Now create another file called main.py ...