Beginner Codes/Python/Modules
49%

Instructions

Importing Modules 📦

Modules are files containing Python code that you can include in your project.

How to Import

import math
print(math.sqrt(16))  # 4.0

Importing specific parts

from math import pi
print(pi)

Using an Alias

import datetime as dt
print(dt.datetime.now())

💡 Did You Know? Modules allow you to split your code into many files, making it much easier to manage large projects.

Your Turn!

Import the random module. Use random.randint(1, 1) to generate a random number (it will always be 1). Print the result.

Help

ModulesExercise 39/7730 XP
❴❵ script.py
python.code
python
Loading...
Terminal
Terminal — python
Beginner Codes Terminal v1.0.0
─────────────────────────────────────
Ready. Click "Run Code" to execute...
Ready
Piston APIPYTHON0 lines