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
- Open a new python file and save it as ‘MessageModule.py’ (you can give any name).
- Write following code inside the module.
def PrintHelloWorldMessage():
print("Hello world")
return
Calling A Module
- Create a new Python file and name it as ‘caller.py’ (you can give any name).
- Inside the file, import module using the import keyword
- After you import the module, you can call the function using module name.function name.
import MessageModule
MessageModule.PrintHelloWorldMessage();
Click to Enlarge