[Go to site: main page, start]

0% found this document useful (0 votes)
3 views1 page

Module Intro

The document introduces Python modules, which are files containing reusable Python code that enhance code organization and maintainability. It explains the benefits of using modules, such as avoiding code duplication and accessing built-in libraries. Additionally, it describes two methods for importing modules in Python: importing the entire module or specific functions directly.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views1 page

Module Intro

The document introduces Python modules, which are files containing reusable Python code that enhance code organization and maintainability. It explains the benefits of using modules, such as avoiding code duplication and accessing built-in libraries. Additionally, it describes two methods for importing modules in Python: importing the entire module or specific functions directly.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

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

You might also like