Tsallaka zuwa abun ciki
Justice Tech School

Modules and import

A module is a .py file. Use import to use it. You can import the whole module, one name with from ... import, or give it a short name with as. The standard library ships with hundreds of modules and you can write your own.

Example
import math
print(math.sqrt(49))
from math import pi
print(round(pi, 3))
import statistics as st
print(st.mean([2, 4, 6]))
print(__name__)

Result

7.0
3.142
4
__main__

Exercise

Import one name from a module.

 math import sqrt

Quiz Test

What does import statistics as st do?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.