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 in Python is


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

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

Python sqrt Function Example

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

# Python SQRT Function

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
  1. Within the first two statements, we used the sqrt Function directly on Positive integers.
  2. Next two statements, We used the sqrt Function on Tuple and List items. If you observe the above Python screenshot, this Math function is working perfectly on them.
  3. Next statement, We tried Python sqrt Function directly on multiple values.
  4. Next, we tried sqrt Function on the String value, and it returns TypeError as output.
  5. Last, we checked the sqrt function against the negative values. As we said earlier, it is displaying the ValueError as output.