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 the following code inside the module
def PrintHelloWorldMessage():
  print("Hello world")
  return





Calling A Module




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



Output


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



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

Query/Feedback


Your Email Id
 
Subject
 
Query/FeedbackCharacters remaining 250