[Tutor] raising number to a power

Stefan Behnel stefan_ml at behnel.de
Thu Feb 25 17:08:16 CET 2010


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.

Stefan



More information about the Tutor mailing list