Lesson 18: import & modules
A module is a file full of ready-made functions someone already wrote for us — instead of reinventing everything, you bring it in with import. For example import math gives math functions, and you call them with a dot: math.sqrt(16) returns 4.0. There's also import random for randomness (its result
A module is a toolbox someone already built. import brings the toolbox, and then you use a tool with a dot: math.sqrt(16).
- import
- import math brings in a whole module so we can use its functions.
- module
- A file of ready-made functions (like math or random) you can import and use.
- from import
- from math import sqrt imports a single name, so you can call sqrt directly without the math prefix.