import
` statement. Here's an example:my_module.py
` with the following code :def greet(name):
print(f"Hello, {name}!")
def add(a, b):
return a + b
You can import this module and use its functions in another file as follows :
import my_module
my_module.greet("Alice") # prints "Hello, Alice!"
result = my_module.add(2, 3)
print(result) # prints 5
You can also import specific functions from a module, like this :
from my_module import greet, add
greet("Bob") # prints "Hello, Bob!"
result = add(5, 7)
print(result) # prints 12
import my_module as mm
mm.greet("Charlie") # prints "Hello, Charlie!"
result = mm.add(4, 6)
print(result) # prints 10​