[Tutor] Question on how to do exponents

Sarma Tangirala tvssarma.omega9 at gmail.com
Tue Feb 7 19:57:02 CET 2012


On 8 February 2012 00:01, Steven D'Aprano <steve at pearwood.info> wrote:

> Sarma Tangirala wrote:
>
>  Is is better to use pow() against **?
>>
>
>
> Advantages of **
>
> - it is shorter to type x**y vs pow(x, y)
> - being an operator, it is slightly faster than calling a function
> - you can't monkey-patch it
>
> Disadvantages of **
>
> - being an operator, you can't directly use it as a function-object
> - it can't take three arguments
> - hard to google for "**"
> - you can't monkey-patch it
>
> Advantages of pow()
>
> - it is a function, so you can pass it around as an object
> - three argument form
> - easy to call help(pow) to see documentation
> - easy to google for "pow"
> - can be monkey-patched
>
> Disadvantages of pow()
>
> - a tiny bit slower due to the function call
> - slightly longer to type
> - can be monkey-patched
>
>
> Weigh up the advantages and disadvantages of each, and make the call which
> is better for you.
>
> (My preference is to use the ** operator.)
>
>
A simple "function call" argument would have done! :D Thanks for the survey!

Anyway, I was wondering about this, if internally pow() actually uses **. :P


>
>
> --
> Steven
>
> ______________________________**_________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/**mailman/listinfo/tutor<http://mail.python.org/mailman/listinfo/tutor>
>



-- 
Sarma Tangirala,
Class of 2012,
Department of Information Science and Technology,
College of Engineering Guindy - Anna University
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20120208/1c12a5c9/attachment-0001.html>


More information about the Tutor mailing list