How to calculate a mod b in python?


Question

Is there a modulo function in the python math library?

Isn't 15 % 4, 3? But 15 mod 4 is 1, right?

1
133
4/29/2015 8:35:51 PM

Accepted Answer

There's the % sign. It's not just for the remainder, it is the modulo operation.

227
6/13/2009 4:59:23 PM

you can also try divmod(x, y) which returns a tuple (x // y, x % y)


Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon