9- Modules in Python
1 min read
In Python, modules allow us to use a set of functions without the need to redefine them. We can group related modules to create a package. Here is an example of a simple module:
def hi(name): print("Hello, " + name)
Save this module as "module1" in your directory.
To use the module, simply import it as follows:
import module1 module1.hi("Ali") # Hello, Ali
Python comes with several built-in modules that we can import and use in our programs. For instance, we can use the "platform" module to get information about the operating system:
import platform print(platform.system()) # Windows
We can also import modules from a package:
import matplotlib.pyplot as plt
If you find this content helpful, please consider SUBSCRIBING to my channel for future updates.
If you would like to get the full video tutorial and a certificate, you can enroll in the course by following this link: https://www.udemy.com/course/python-for-researchers/?referralCode=886CCF5C552567F1C4E7