MODULES IN PYTHON – CLASS 11 (CBSE)
1. What is a Module?
A module in Python is a file that contains Python code—functions, variables, and
classes—written to perform a specific task.
● It helps in organizing code.
● Makes programs reusable and easy to maintain.
● Any Python file with extension .py can be used as a module.
Example:
A file named [Link] or [Link] is a module.
2. Why Do We Use Modules? (Benefits)
● Reusability: Use functions written earlier in new programs.
● Simplicity: Divide a large program into smaller parts.
● Avoid Repetition: Common functions kept in modules.
● Better Organization: Code is cleaner and structured.
● Library Support: Python provides many built-in modules.
3. Types of Modules
1. Built-in Modules
Modules already available in Python.
Examples:
● math
● random
● datetime
● statistics
● os
2. User-defined Modules
Modules created by the programmer in a separate .py file.
Example:
Creating [Link] with functions and importing it into another program.
4. Importing Modules in Python
Python provides multiple ways to import modules.
A. import module_name
import math
print([Link](25))
● Access functions using module_name.function_name.
●
●
● import math as m print([Link])
●
● D. from module_name import *
from math import *
print(sin(0))