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