+ 2
What is Sqrt() in Python
I'm an intermediate in Python. And I was doing python for finance and I came across this thing called sqrt() and Idk what that is can I have help? https://www.sololearn.com/learning/1139/5194/13662/1 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Link
18 Respostas
+ 15
sqrt() is a a python function used in a module called "math". This function is used to calculate the square root of the number.
Examples:
print(sqrt(36))
print(sqrt(49))
print(sqrt(81))
Output:
6.0
7.0
9.0
+ 7
Hey Lamron as you state it's a function of module math.
So first import math and call the function from it.
Import math
print(math.sqrt(x))
+ 5
Julian Zimpel exactly that, but for **import** command make sure everything is in lowercase
+ 5
Julian Zimpel you can import some functions from modules, but I would recommend importing the whole module.
**as** keyword allows you to refer to that module with a different name.
Let's say we have a module called **ComputerScienceModule**
It's too long to type each time, therefore you can use **as** keyword to give it a different name in your program.
Example:
import ComputerScienceModule as csm
print(csm.function(value))
+ 3
Square root.
You can get the same result by calulating number x number
(Or num * num) to get the result.
You can do the opposite by dividing the num by num. Ex: 64 // num || or (float) 64/8
+ 2
Gemuh Hans Ujjwal Gautam Mr Williams , guys, great examples, but don't forget:
square root operation is integer to float division. i.e. 36/6 = 6.0
It's not a floor division, i.e. 36//6 = 6
Therefore, if we do something like:
print(math.sqrt(36))
We will get 6.0
Because we do: 36/6
Not: 36//6
See example:
https://code.sololearn.com/cn5xPOtDRqNU/?ref=app
+ 2
Thanks For answering my questions :)
+ 1
š
indeed
+ 1
Lamron your code is fine with:
from math import sqrt as sqrt
print(sqrt(x))
+ 1
Lamron thats right, thanks for the reminder.
0
I need help
0
sqrt() is a function in the math module. It's becomes available when you import it at the start of your code.
Import math
print(math.sqrt(9)) = 3
print (math.sqrt(16)) = 4
And so on
0
sqrt() is a python function in . Math module
Sqrt (Square Root ) it will calculate the square root of a function
print(sqrt(9))
O/P -- 3
0
Square Root
0
Its square root of a number. So example if you
Import Math
Print(math.sqrt(36))
You will get 6
0
After importing, you could check the number of functions within via print(len(dir(math))); it has 61 functions. If you don't need all of those, importing them is just going to slow the program down unnecessarily. [This site](https://www.w3schools.com/JUMP_LINK__&&__python__&&__JUMP_LINK/module_math.asp) is excellent for exploring the depths of python and other languages.
0
Why doesn't this support markdown?
0
Try these both to see if you notice the difference:
from math import sqrt
#one function to parse before use
print(sqrt(81))
#delete the above
import math as iloveslowapps
#61 functions to parse before use
print(sqrt(81)
#by the way, I'm also working through the python for finance