+ 5

pow() function

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

23rd May 2020, 9:49 AM
M Tamim
M Tamim - avatar
3 odpowiedzi
+ 3
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
23rd May 2020, 10:14 AM
Ashish Gupta
+ 2
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.
23rd May 2020, 10:09 AM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
- 1
The third argument is for modulus(%)
24th May 2020, 8:53 AM
Pankaj Jain
Pankaj Jain - avatar