23
loading...
This website collects cookies to deliver better user experience
import
keyword, followed by the function name. import function_name
import math
, this statement tells the Python interpreter to load the contents of the module into memory, that is making the functions and/or classes stored in the math module available in your current program file. After importing a module, you have can make use of all the functions or classes it contains. module_name.function_name
import math
n = math.sqrt(25) # get the square root of 25
print (n)
>>> 5.0
from
keyword with the import
statement.from module_name import function_name
from math import sqrt
n = sqrt(25) # get the square root of 25
print (n)
>>> 5.0
from module_name import function_a, function_b, function_c
from math import sqrt, radians
n = sqrt (25) # get the square root of 25
c = radians (180) # convert degree value into radians
print (n)
>>> 5.0
print (c)
>>>> 3.141592653589793
import math as mth # given math module an alias `mth`
n = mth.sqrt(25) # get the square root of 25
print (n)
>>> 5.0
from math import radians as rad # given the function radians an alias `rad`
c = rad(180)
>>> 3.141592653589793
from math import *
from math import *
n = sqrt(25) # get the square root of 25
print (n)
>>> 5.0