Modules are the logical unit that comprises of functions that can be reused in other multiple files.
Consider module as the dll or the external files which can be referred in the file.
Let’s see how to create a module. Create a new file called “modules.py”

Add a function as shown below,

This function just echoes the data whatever is passed on.
Let’s import this module in the existing file that we created earlier. I am importing “modules” file in StringFormatting.py file that I created earlier.
We need to use “import” statement to refer the modules.

In the line number 1, we have imported modules.
In line number 7, we have called echo method which takes “test” as an input.
Please ignore line number 3 and 4, as these code lines are part of previous example.
Let’s execute this program and we should see that the echo function gets executed and echoes the data whatever we have passed.
Output:

I believe, this would have given you an fair idea about modules. There are many advantages of using modules in python like code modularity, maintainability, etc.
There are several modules provided by Python itself which provides set of core features like to use the features of OS, there is a module called os which needs to be imported.
sys module contains services that Python offers that mostly involve system-specific items.

Likewise, we can use different set of features by importing the corresponding modules.
Great content 🙂 Thank you
LikeLike