More

    How to Create A Module In Python

    Hey fellas! In this article we’re gonna discuss about How to Create A Module In Python. Python is a powerful as well as friendly programming language. It is used to develop desktop apps, web, as well as pretty awesome softwares. Python is also a powerful tool for data science. So, before going further into the topic lets know What is a Python Module?

    A Python module is simply a python file consisting of python codes that may include classes, functions, variables,etc. It’s a code written in python which we can reuse for our convenience. With this simple definition lets move on to our main topic.

    How to Create A Module In Python?

    Creating a module in Python is as simple as creating a python program. The only two steps you have to follow are:

    Step 1: Write a bunch of codes for module.

    First of all create a python file. You can use your favorite text editor and start. Write the functions you want to have in your code and save it as a Python executable file (.py file).

    The codes I have written for examples are listed below:

    def add(a,b):
    return(a+b)

    def subt(a,b):
    return(a-b)

    def mult(a,b):
    return(a*b)

    def divide(a,b):
    return(a/b)

    After I wrote these codes I saved it as newmath.py because I’m doing math here and it’s easy to remember. You can name a module as you like like tonystark.py, venom.py but be sure to make it easy to remember so that you can use it as per necessity.

    Also read our article on How to make money with Whatsapp. Interesting, isn’t it?

    Step 2: Use it in your code

    Next step is also very easy. You have to import the module you have created by using

    import module_name

    import newmath   (in our case)

    The thing left to do is using it. You can access the functions in your module by using

    module_name.function(arguments)

    newmath.add(1,2)                             In our case.

    The picture below will help you understand it more clearly. If you have any queries about the post or about Python feel free to comment or email us. Thanks for reading.

    Recent Articles

    How to get free .edu Email | 2020 | Working [April Method]

    How to get free .edu Email - This is the second tutorial posted this year about method to get free .edu email. This method...

    Skillshare Free | Download any course from Skillshare | 2020

    Skillshare Free  What is Skillshare? Skillshare is an American online learning community for those who want to learn from educational videos. They had free as well...

    Read any articles for Free | How To Bypass Paywalls Subscription | 2020

    Read any articles for Free - No matter either you are reading news or reading some tutorials and write-ups in internet. Sometimes we all...

    How to Transfer Files from One Cloud to Another | 2020 |

    How to Transfer Files from One Cloud to Another - Please follow the steps give below carefully for high speed transfer/backup of files from...

    Get Free edu Email 2020 | Unlimited Google drive | With Proof

    Get Free edu Email  Providing new methods for .edu emails has always been the plus point of TechRim. Every year we present with...

    Related Stories

    Leave A Reply

    Please enter your comment!
    Please enter your name here

    Stay on op - Ge the daily news in your inbox