Python Modules

A file containing a group of functions, Classes, and Variables which you wanted to include in your applications is called as a Module.

You can also include codes whichever you want and File must be saved extension And Every Python file acts as a Module.

The advantage of python Module is that, once we define any function in a Module and save that Module with the extension .py and you can use this function in any other source file by using the Import statement.

Let us consider an example:

A file which contains the Addition functionality and product functionality and saved as which is nothing but Module.

And I am creating another one module called, here I am using the Addition and Product function but instead of defining the function here, I am going to import the same function from the Module by using the import keyword.


def add(a,b):
    print("Performing the addition Operation")

print("The sum:",a+b)
def product(a,b): 
    print("Performing the multiplication Operation")
print("The product:", a*b)

Possible ways to import a Module

There are several inbuilt Modules are available inside the Python, we can use these Modules in our applications easily by importing the respective Functions.

ex: Math Module, Random Module, time Module, and threading Module, etc..

Let us see what are the various functions available in the Math Module

import math


Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions