GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing www.geeksforgeeks.org — Python math.sqrt() function | Find Square Root in Python - GeeksforGeeks Python math.sqrt() function | Find Square Root in PythonLast Updated : 14 Feb, 2025 math.sqrt() returns the square root of a number. It is an inbuilt function in the Python programming language, provided by the math module. In this article, we will learn about how to find the square root using this function. Example:
Output 0.0 2.0 1.8708286933869707 We need to import
math.sqrt() syntax
Parameter:
Returns:
math.sqrt() examplesLet's look at some different uses of math.sqrt() . Example 1: Check if number is primemath.sqrt() can be used to optimize prime number checking. We only need to check divisibility up to the square root of the number.
Output prime Explanation
Example 2: Finding hypotenuse of a triangleWe can use math.sqrt() to find the hypotenuse of a right-angled triangle using the Pythagorean theorem.
Output The value for the hypotenuse would be 25.079872407968907 Explanation
Error handlingmath.sqrt() does not work for negative numbers. It raises a ValueError if we pass a number less than 0.
Output Traceback (most recent call last): Explanation
Comment Explore |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |