[Tutor] Question on how to do exponents

bob gailer bgailer at gmail.com
Tue Feb 7 20:20:27 CET 2012


On 2/7/2012 1:57 PM, Sarma Tangirala wrote:
>
> Anyway, I was wondering about this, if internally pow() actually uses 
> **. :P
>
 >>> from dis  import dis
 >>> dis(lambda a,b:a**b)
   1           0 LOAD_FAST                0 (a)
               3 LOAD_FAST                1 (b)
               6 BINARY_POWER
               7 RETURN_VALUE
 >>> dis(lambda a,b:pow(a,b))
   1           0 LOAD_GLOBAL              0 (pow)
               3 LOAD_FAST                0 (a)
               6 LOAD_FAST                1 (b)
               9 CALL_FUNCTION            2
              12 RETURN_VALUE

Now you know, and you know how to find out!

To delve any deeper you'd have to inspect the c source for pow.
I'd assume it uses the c exponent operator

-- 
Bob Gailer
919-636-4239
Chapel Hill NC



More information about the Tutor mailing list