Learn and Learn

Learn And Learn - great place for tutorials, references and how-to

How to Calculate Square Root in Python using sqrt() Function

To find out the square root in Python Programming Language you can use math.sqrt() function of Standard Library.

Python sqrt() Function

math.sqrt() function exists in Standard math Library of Python Programming Language. The purpose of this function is to calculate squar root of a given value x. x must be greater than zero (x>0).


Python sqrt() Function Syntax

The syntax of sqrt function in python is:
math.sqrt( x )


Python sqrt() Function Parameters

x – Any valid Python positive number. This parameter is required.
Note: if the x parameter is not a number returns an error.


Python sqrt() Function Compatibility

Python 2.x – Yes
Python 3.x – Yes


Python sqrt() Return Value

sqrt() function will return an integer or a floating point number after calculating squar root. The return value will always be greater than zero.


Python sqrt() Function Examples

Output of Python sqrt() function:

ValueError: math domain error


LearnAndLearn.com © 2018 - All rights reserved