2/10/26, 5:05 PM Chapter Wise
Module Intro
Introduction to Python Modules
A Python module is a file that contains Python code—functions, classes, or variables—that
you can reuse in other programs. Modules help break large programs into smaller,
manageable, and organized pieces. They promote code reusability, readability, and
maintainability.
Python comes with many built-in modules (like math, random, statistics), and you can also
create your own custom modules.
Why Use Modules?
Avoid rewriting the same code.
Organize related functions together.
Share and reuse code across multiple projects.
Access powerful built-in libraries.
Importing Modules
There are two main ways to import modules in Python:
1. Using import <module>
Imports the entire module.
You must use the module name as a prefix.
import math
print([Link](16)) # 4.0
print([Link]) # 3.141592653589793
2. Using from <module> import <name>
Imports specific functions/constants directly.
You can use them without the module prefix.
from math import sqrt, pi
print(sqrt(25)) # 5.0
print(pi) # 3.141592653589793
[Link]:8000/articles/?grade=9&subject=21 1/1