Labs ICT
โญ Pro Login

Modules

1 min read | Python Tutorial
โญ

Want the full learning experience?

Get structured courses, certificates, projects, and instructor support with LabsICT Pro.

Explore Pro Courses

Modules

A module is a .py file containing functions, classes, and variables. Use import to bring its contents into your program.

Importing a Module

import math

print(math.sqrt(16))
print(math.pi)

from random import randint
print(randint(1, 10))

Creating Your Own Module

Save this as mymodule.py:

def greet(name):
    return f"Hello, {name}!"

PI = 3.14159

Then use it in another script:

import mymodule

print(mymodule.greet("Alice"))
print(mymodule.PI)
print(dir(mymodule))

๐Ÿงช Quick Quiz

How do you import only a specific function from a module?