Python sqrt

The Python sqrt function is used to find the square root of a specified expression or a specific number. The syntax of the math sqrt Function is


Number: It can be a number or a valid numerical expression.

  • If the number argument is a positive integer, the Python math sqrt function returns the square root of a given value.
  • If it is Negative integer, it returns ValueError.
  • And if it is not a number, it returns TypeError.

Python sqrt Function Example

The Python sqrt function finds the square root of a given number. In this example, We are going to find the square root of different data types and display the output

  1. Within the first two statements, we used directly on Positive integers to calculate the python square root.
  2. Next two statements, We used it on Tuple and List items. If you observe the above Python screenshot, this math method is working perfectly on them.
  3. Next statement, We tried sqrt Function directly on multiple values to find the square root in python programming.
  4. Next, we tried on the String value, and it returns TypeError as output.
  5. Last, we checked this against the negative values. As we said earlier, it is displaying the ValueError as output.
import math

Tup = (10.98, 20.26, 30.05, -40.95 , 50.45) # Tuple Declaration
Lis = [-10.98, 32.65, -39.59, -42.15 , 35.97] # List Declaration

print('Square Root of Positive Number = %.2f' %math.sqrt(10))
print('Square Root of Negative Number = %.2f' %math.sqrt(25))

print('Square Root of Tuple Item = %.2f' %math.sqrt(Tup[2]))
print('Square Root of List Item = %.2f' %math.sqrt(Lis[4]))

print('Square Root of Multiple Number = %.2f' %math.sqrt(10 + 45 - 10))

print('Square Root of String Number = ', math.sqrt('Python'))
Python SQRT Function