Python sqrt() method is used to get the square root of the given number. sqrt() method can return square of any number. This method comes under math
module.
Basic Syntax
Following is the basic syntax for sqrt() method in Python:
sqrt(number)
And the parameters are:
Parameter | Description |
---|---|
number | The number whose square root should be returned |
Return Value
sqrt() method in Python will return the square root of the given number. If the value is less than 0 then it will return Runtime Error.
Examples
Following are the examples for sqrt() method in Python:
Example 1
1 2 3 4 5 6 | # Python Program for sqrt() method import math a = 64 result = math.sqrt(64) print('The square root of 64 is %0.3f'%(result)) |
The output should be:
The square root of 64 is 8.000
Example 2
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | # Python program for sqrt() method import math print("The square root of 9: ") print(math.sqrt(9)) print("\nThe square root of 9.9: ") print(math.sqrt(9.9)) print("\nThe square root of 0: ") print(math.sqrt(0)) print("\nThe square root of 8: ") print(math.sqrt(8)) |
The output should be:
The square root of 9:
3.0The square root of 9.9:
3.14642654451
3.0The square root of 9.9:
3.14642654451
The square root of 0:
0.0
The square root of 8:
2.82842712475