0

why would you use %= in Python?

I understand how it works, but in what situation would you use this?

4th Apr 2018, 5:00 PM
Kevin Sorensen
Kevin Sorensen - avatar
1 Resposta
+ 1
Modulo operator is not a python-specific thing. It is widely used in mathematics, for example in calculating greatest common divisor: ----- from functools import reduce numlist = [54, 144, 18] def gcd(num1, num2): res = num1 % num2 if res == 0: return num2 else: return gcd(num2, res) print(reduce(gcd,numlist)) ----- Modulo is the key tool for Fermat's Little Theorem primality test, and has lots of other uses.
4th Apr 2018, 5:53 PM
strawdog
strawdog - avatar