How to use the pow() function to calculate power and modulus in Python

1 Answer

0 votes
n1 = 3
n2 = 3

pw = pow(n1, n2)
print(pw)

result = pow(n1, n2, 5)  # 3 * 3 * 3 = 27 : 5 = (5, 2) = 5 * 5 + 2 = 27
print(result)


'''
run:

27
2

'''

 



answered Dec 15, 2018 by avibootz
...