![]() | ![]() |
The import statement can be used to access the definitions within a module via the dot operator.
Start IDLE.
Navigate to the File menu and click New Window.
Type the following:
import math
print("The PI value is", math.pi)
Import with renaming
Example
Start IDLE.
Navigate to the File menu and click New Window.
Type the following:
import math as h
print(“The PI value is-“,h.pi)
Discussion
In this case, h is our renamed math module with a view helping save typing time in some instances. When we rename the new name becomes valid and recognized one and not the original one.
From...import statement Python.
It is possible to import particular names from a module rather than importing the entire module.
Example
Start IDLE.
Navigate to the File menu and click New Window.
Type the following:
from math import pi
print("The PI value is-", pi)