pow() works but sqrt() not!?

Fredrik Lundh fredrik at pythonware.com
Thu Jan 4 13:18:05 CET 2007

"siggi" wrote:

> Nope, I did not! But I used sqrt(9), and not math.sqrt(9). The latter works
> excellent, thank you! From now on, I will use "import math" and
> "math.fuction()" for EVERY mathematical function, even for pow() etc. just
> to be on the safe side!

pow and math.pow are two slightly different things, though.  pow() works on
any type that supports power-of operations (via the __pow__ hook), while
math.pow treats everything as a 64-bit float:

>>> math.pow(2, 200)

>>> pow(2, 200)

pow also takes a third modulo argument (pow(x,y,z) is equivalent to pow(x,y) % z,
but can be implemented more efficiently for certain data types).


More information about the Python-list mailing list