All courses › Programming with Python › Modules and import
Modules and import
A module is a file of ready-made functions you can use in your own program. The standard library has many, such as math, random and csv. You can also make your own modules by putting functions in a separate file and importing it.
import the whole module, use math.sqrt
import specific names
import with a shorter name
Symbols
| mathematical functions | ||
| random numbers | ||
| read and write table files |
Example
The hypotenuse of a triangle with legs 3 and 4:
gives 5.0.
Avoid from module import *. Then you no longer know where names come from.
Practise files, errors and modules for free →