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
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 a 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 will find the square root of different data types and display the output.
- Within the first two statements, we used directly on both the Positive integers to calculate the Python square root.
- 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.
- Next statement, We tried this Python math sqrt Function directly on multiple values to find the square root in this programming.
- Next, we tried on the String value, and it returned TypeError as output.
- Last, we checked this against the negative values. As we said earlier, it is displaying the ValueError as output.