1

Is there a reason why Python's built-in pow allows 3 arguments, but math.pow allows only 2?

Of course we could lazily say, "because that's how it's designed".

But does anyone know the reason behind this design decision?

Edit:

To clarify, I understand what the difference is, but I'm wondering why we need both. Why not just have the the 3 argument built-in pow.

pushkin
  • 9,575
  • 15
  • 51
  • 95
  • 1
    I don't believe this is a duplicate. I'm not asking about what the differences are. I just want to know why we need both of them. Is there a reason to not always use the built-in function? – pushkin Nov 13 '15 at 03:56
  • I haven't benchmarked it, but I'd imagine that `math.pow` is more efficient since it only handles floats (and calls the underlying C libraries), while built-in `pow` is more versatile, but necessarily less efficient since it has to look up the `__pow()__` (or `__rpow()__` and/or `__lpow()__` as needed) methods in its parameters. – rmunn Nov 13 '15 at 07:02

1 Answers1

0

Code comments say this:

Equivalent to x**y (with two arguments) or x**y % z (with three arguments)

Some types, such as ints, are able to use a more efficient algorithm when invoked using the three argument form.

Jared Mackey
  • 3,998
  • 4
  • 31
  • 50
  • I understand that, but then why not always use the built-in `pow`. Are there cases where it's less efficient? – pushkin Nov 13 '15 at 03:51