Modules & Packages in Python
Chapter 19: Modules & Packages
4 short lessons, with 3D animations, quizzes and coding tasks.
The lessons
Importing modules
A module is a file of ready-made code; import math puts the name math on your desk, and you reach its tools with a dot, math.sqrt(16).
Handy modules: random, collections, datetime
random picks by chance, collections.Counter counts things in one line, and datetime.date does calendar maths.
Your own modules
Any .py file is a module: put your helpers in helpers.py, and a program next to it can import helpers and use them.
Packages, and installing more with pip
A package is a folder of modules (with an init.py file), reached with dots like from shapes.square import area, and pip installs packages other people have published.