sqrt() function is an inbuilt function in Python programming language that returns the square root of any number.
Syntax: math.sqrt(x) Parameter: x is any number such that x>=0 Returns: It returns the square root of the number passed in the parameter.
0.0 2.0 1.8708286933869707
Error: When x<0 it does not executes due to a runtime error.
Traceback (most recent call last): File "/home/67438f8df14f0e41df1b55c6c21499ef.py", line 8, in print(math.sqrt(-1)) ValueError: math domain error
Practical Application : Given a number, check if its prime or not.
Approach: Run a loop from 2 to sqrt(n) and check if any number in range (2-sqrt(n)) divides n.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.