Articles → Python → Create Our Own Module In Python And Consume It

Create Our Own Module In Python And Consume It






What Is A Module?





Creating A Module




  1. Open a new python file and save it as ‘MessageModule.py’ (you can give any name).
  2. Write following code inside the module.
def PrintHelloWorldMessage():
  print("Hello world")
  return





Calling A Module




  1. Create a new Python file and name it as ‘caller.py’ (you can give any name).
  2. Inside the file, import module using the import keyword
  3. After you import the module, you can call the function using module name.function name.
import MessageModule
MessageModule.PrintHelloWorldMessage();




Picture showing the output of calling your own custom module in python

Click to Enlarge


Posted By  -  Karan Gupta
 
Posted On  -  Thursday, April 18, 2019

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250