Use ** instead of pow() in Python

less than 1 minute read

I ran across Python code using pow(10,-3) instead of 10**(-3).

[1] %timeit 10**(-3)
8.31 ns ± 0.0267 ns per loop (mean ± std. dev. of 7 runs, 100000000 loops each)

[2] %timeit pow(10,-3)
163 ns ± 3.33 ns per loop (mean ± std. dev. of 7 runs, 10000000 loops each)

So it seems unless I need the special functionality of pow(), I should use ** instead.

Categories:

Updated:

Leave a comment