← All lessons

import: bring in a module

Sign in · Sign up

Lesson 7.0

You don't have to write everything yourself: Python has ready-made modules. import brings in a module, and after that you reach its contents with a dot.

import math

print(math.pi)      # 3.141592653589793
print(math.sqrt(9)) # 3.0

math is a module, not a function, so math() won't work. pi is a number and needs no brackets, while sqrt(9) is a function and needs them.

Write a program: import math, print π, then math.sqrt of the number number that the check sets.

Hint

import math brings in the module, after that you reach it with a dot.

The constant is math.pi, the root is math.sqrt(...), the brackets are required. Print math.pi first, then the root of the number.