[Tutor] raising number to a power

Ricardo Aráoz ricaraoz at gmail.com
Thu Feb 25 19:34:39 CET 2010


Stefan Behnel wrote:
> Monte Milanuk, 25.02.2010 16:47:
>   
>> Is there a benefit (besides brevity) one way or the other between using:
>>
>> import math
>> ...
>> math.pow(x,y)  # x raised to the power y
>>
>> vs.
>>
>> x**y
>>
>> ?
>>     
>
> You might also be interested in this:
>
> http://docs.python.org/reference/datamodel.html#emulating-numeric-types
>
> The difference is that math.pow() is a function that works on two float
> values, whereas '**' is an operator that can work on anything, including
> your own classes. It's the number types that define the operator as meaning
> the power function, not the operator itself.
>   

So why would the coders of the math module go to the trouble of creating
the pow function? Did they create a sum function and a subtract function?
It seems to me the question has not been properly answered. When to use
one, when to use the other?
If you don't know the answer it's all right. I don't know it either.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100225/3ade81a1/attachment.html>


More information about the Tutor mailing list