Member-only story
Interview question: What do you understand by module in Python?
Python is a language that has built in modules and modules that can be made within a program.
Modular programming is the practice of segmenting a single, complicated coding task into multiple, simpler, easier-to-manage sub-tasks. We call these subtasks modules. Therefore, we can build a bigger program by assembling different modules that act like building blocks.
Putting modules of smaller chunks of code in a large application has a lot of benefits, such as:-
- Simplicity,
- Flexibility,
- Reusability, and
- Scope.
A document with definitions of functions and various statements written in Python is called a Python module.
In Python, a module can be defined in three ways:-
- Python allows for creation of modules,
- A module can be written in the C programming language and dynamically inserted at run-time. The reason for this is because Python itself is written in C. When a program is written in Python, it is executed in a Python interpreter, which is written in C, such as re (regular expression).
- Python has several builtin modules that are included in the Python interpreter, such as itertools.