Standard Library Module in Python | CBSE Class 12
Standard Library Module in Python
In this tutorial, we shall be learning about some standard library modules in python. Before beginning the main topic, first of all we need to know about “What is a module in python”
What is a module in python?
A module in something (a, file) that contains some variable and constants some functions (predefined), objects etc.
Standard library module in python :- A (python file) can be used in your program to get predefined functionality in your python program. Here, you need not to write any extra python code to use it in a python program.
In order to use a module, you just need to first import that module in your program and then you can use all the functions defined in that module in your program.
Definition: –
Technically we can say “a python module is a file (.py) which contains some enables and consonant functions and objects in it which can be used in other python programs by importing it”
A module is always having some predefined python functions for use only by calling in your program after importing the module
Example
in order to use functions of math module, you need to writing the import statement at the top of your python program of as follows
import math
New, you can use any math library’s function as by writing.
math < function-name >
<function-name> can use any function that is already defined in math module
Program
>>> import math
>>> math. Sort (25)
Output >>> 5
2. Advantages of using module in python
A module is a separate unit (.py file) in itself. It Facilitates the following benefits to a python program
- It reduces the complexity of a python program.
- It creates a number of well-defined documented boundaries within the program.
- It also can be reused in other programs without having to rewrite the same code again & again.
For example, if someone has created a module say ‘play Audio’ to play different audio formats, coming from different sources, e.g., mp3player, FM-radio player, DVD player etc. now, while writing a different program, if someone wants to incorporate FM-radio into it, he needs not re-write the code for it. rather, he can use the FM-radio functionality from play audio module. Is not that amazing? re- usage without any re-work – well, that’s the beauty of modules.
Exam Time
Chapter : Using Python Modules
IMPORTANT QUESTIONS : Asked in examinations of CBSE Class 12th Computer Science
Read more
-
structure of module in python
-
arithmetic operators
-
operators in python
-
types of operators
-
logical operators
-
membership operators
-
standard library module
- Identifiers in python