Python Modules
In Python, modules are files containing Python code that define functions, classes, and variables. They provide a way to organize code into reusable units and enable modular programming by allowing components to be imported and used in other Python programs or modules.
def greeting(name):
print("Hello, " + name)
person1 = {
"name": "John",
"age": 36,
"country": "Norway"
}
Python Online Compiler
Import module
import mymodule
mymodule.greeting("John")
Python Online Compiler
Import from module
from mymodule import person1
print (person1["age"])
Python Online Compiler
Built-in modules
import platform
x = platform.system()
print(x)
Python Online Compiler