A module in Python is a file containing Python code
(functions, classes, and variables) that can
be reused in other programs. Python provides several ways to
import modules.
1. Importing an Entire Module
Syntax:
import module_name
Example:
import math
print([Link](25))
print([Link](5))
Output:
5.0
120
2. Importing Specific Functions from a Module
Syntax:
from module_name import function_name
Example:
from math import sqrt, factorial
print(sqrt(36))
print(factorial(4))
Output:
6.0
24
3. Importing All Functions from a Module
Syntax:
from module_name import *
Example:
from math import *
print(sqrt(49))
print(pow(2, 3))
Output:
7.0
8.0
4. Importing a Module with an Alias
Syntax:
import module_name as alias_name
Example:
import math as m
print([Link](64))
print([Link])
Output:
8.0
3.141592653589793