Python sqrt

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

math.sqrt(number);

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 screenshot, this math method is working perfectly on them.
  3. Next statement, We tried this 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.
Python sqrt Function