+ 7
Can you please explain the output of this code?
my_variable = pow(2,2,3) print(my_variable) Answer is 1
3 Answers
+ 8
https://www.w3schools.com/JUMP_LINK__&&__python__&&__JUMP_LINK/ref_func_pow.asp
pow(x, y, z)
Returns (x**y) % z
Hence,
pow(2,2,3) is equivalent to
(2**2) % 3
4 % 3
1
+ 2
If two parameters are passed to the pow() function (for example, x and y), it returns x to the power of y. If a third parameter is present, it raises x to the power of y and then returns the result modulus that 3rd value. As of the case here:
2^2 = 4, 4 % 3 = 1
0
2



