
PYTHON — Main Module Exercise Python
The most dangerous phrase in the language is, ‘We’ve always done it this way.’ — Grace Hopper
PYTHON — Greeter Module Solution Python
Talk is cheap. Show me the code. — Linus Torvalds
medium.com
Adding a Main Module in Python
In this exercise, you will learn how to create a main module in Python that imports a function from another module and then calls that function with a specific argument. Let’s get started!
Exercise Instructions
- Create a new module called
main.py. - Import the
greet()function from thegreeter.pymodule. - Call the
greet()function with the string"Real Python"as an argument.
Code Implementation
Below is the Python code to accomplish the above exercise instructions:
# main.py
# Import the greet function from the greeter module
from greeter import greet
# Call the greet function with the argument "Real Python"
greet("Real Python")Explanation
- We start by importing the
greet()function from thegreetermodule using thefrom ... import ...syntax. - Then we call the
greet()function with the argument"Real Python".
This exercise helps in understanding how to create a main module in Python and utilize functions from other modules within the main module.
By completing this exercise, you will have gained hands-on experience in creating and using a main module in Python.
Feel free to try out the code and experiment with different arguments to further solidify your understanding of using main modules in Python.






