Square root of number python

Use the math module instead of the cmath module; the latter is for complex numbers only:

>>> import math
>>> print math.sqrt(25)

For what it’s worth, the cmath result is correct, if you expected a complex number. You could take just the .real component of the result, but since there is a regular floating point equivalent in the math module there is no point in having your computer do the extra work.

Browse More Popular Posts

Leave a Comment