--Originally published at Quirino´s Projects
Python is a really powerful programing language, we can do a lot of things with it, but sometimes the stock python is not enough when we want to do other things easily without having to do our own functions. For example if we wanted to get the Squared root of a number, we couldn’t do it with the basic mathematical operations python gives us in this case we need to import the sqrt function in the math library
The way this works is like this:
from math import sqrt
from
from the following module
import
Import this
The way this is used is that import checks the math module, then inside it, it takes the sqrt function
This way we only import sqrt function inside math, but if we wanted to import the whole module we could also do
import math
This would let us use everything contained in math, but now to access a method in math we would need to do
print (math.sqrt(6))
Because Python wouldn’t know if we have a sqrt function in our program, so we need to specify from were we are taking this function
Also, we could import some function or a variable from a module, and rename it as we want then use it
from math import sqrt as squaredRoot
print (SquaredRoot(5))
>> 2.23606797749979