
Python Modules Tutorial
1. Introduction to Modules
import math
2. Accessing Module Functions
print(math.sqrt(25))
3. Importing Specific Functions
from math import sqrt print(sqrt(25))
4. Aliasing Modules
import math as m print(m.sqrt(25))
5. Using Multiple Functions from a Module
from math import sqrt, factorial print(sqrt(25)) print(factorial(5))
6. Understanding the Module Search Path
import sys print(sys.path)
7. Adding to the Module Search Path
sys.path.append('/path/to/directory')
8. Creating Your Own Module
# mymodule.py def hello_world(): return "Hello, World!"
9. Importing Your Own Module
import mymodule print(mymodule.hello_world())
10. Reloading a Module
import importlib importlib.reload(mymodule)