"Oscar Benjamin" <oscar.j.benja...@gmail.com> wrote in

Then you want operator.pow:

import operator
operator.pow(3, 2)
9

math.pow is basically the (double)pow(double, double) function from
the underlying C library. operator.pow(a, b) is precisely the same as
a**b.

So how is operator.pow() different from just pow()?

There's no need to use strings if you're working with integers in
Python. The results with int (not float) will be exact and will not
overflow since Python's ints have unlimited range (unless your machine
runs out of memory but that only happens with *really* big integers).

Yes, that's the idea. I haven't really used Python before, so was just kicking the tyres a bit and got some odd results. This forum has been great though.

If you want to do computations with non-integers and high precision,
take a look at the decimal and fractions modules.
http://docs.python.org/2/library/decimal.html
http://docs.python.org/2/library/fractions.html

There is also a good third party library, sympy, for more complicated
exact algebra:
http://sympy.org/en/index.html

Thanks a lot for the references, I'll definitely check them out.
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to