pow() function | SoloLearn: Learn to code for FREE!


pow() function

What does the third argumeny of pow() function do? And is that function is somehow related to math.pow() ??

5/23/2020 9:49:57 AM

M Tamim

3 Answers

New Answer


Third argument is used for modulus of result generated by first two. For example pow(2,4,3) Here 2 raise to power 4 which gives 16 and after modulus with 3 you get 1 as final result. This third argument is optional...use it according to your convenience. Yes its similar to math.pow() which we use in java but you don't get optional modulus there


As you can see by using: help(pow) the third argument is the modulo: pow(x, y, z) == x**y % z So, pow(4, 5, 6) equals 4**5 % 6, so 1024 % 6, which is 4 (1024/6=170R4). AFAIR, math.pow only accepts the first two arguments. Plus, it always returns a float, even if the arguments are int.


The third argument is for modulus(%)