On Fri, Jan 15, 2021 at 5:56 AM <2qdxy4rzwzuui...@potatochowder.com> wrote: > > On 2021-01-14 at 17:54:55 +0000, > Alan Gauld via Python-list <python-list@python.org> wrote: > > > My question is: why do we even have a sqrt() in the > > math module given that pow() and ** are already there? > > Probably because the standard C math library has such a function, and > Python's math module is (or at least was) supposed be a thin wrapper > around that library. > > For completeness, C doesn't have a exponentiation operator.
Also, the math module works specifically with floats. Sometimes that's what you want, other times it's not. >>> pow(-2, 0.5) (8.659560562354934e-17+1.4142135623730951j) >>> (-2)**0.5 (8.659560562354934e-17+1.4142135623730951j) >>> from math import sqrt; sqrt(-2) Traceback (most recent call last): File "<stdin>", line 1, in <module> ValueError: math domain error >>> from cmath import sqrt; sqrt(-2) 1.4142135623730951j ChrisA -- https://mail.python.org/mailman/listinfo/python-list