In Python, a module is a text file containing Python code.
Python Modules - What and Why
- The purpose of a module is to add functionality to Python, usually by defining new functions and other objects. It basically tells Python what to do if one of these is encountered in the command lines.
- A Python module may be consist of a single plain text file (with the extension ".py" instead of ".txt") containing one or more functions. If you're curious, you can open a .py file with most text editors (such as Notepad++) or a web browser (e.g. Google Chrome or Mozilla Firefox).
- Python doesn't automatically "know" the contents of all modules present. So if you'd like to use a function from some module, you should first
importit. This comes down to "asking" Python to read and remember all contents of it.
- Writing your own (simple) module is not difficult at all and may save time and effort.