4 ms·
In both cases, b * (a // b) + a % b = a, which is often a behavior that you want. In some other languages, the % operator (IMO wrongly) takes the sign of a, ma
by jacobolus 10y ago
In both cases, b * (a // b) + a % b = a, which is often a behavior that you want.
In some other languages, the % operator (IMO wrongly) takes the sign of a, making it more like a “remainder” operator than a “modulo” operator, whereas in Python % (IMO correctly) takes the sign of b.
I also agree that this should be thought of as “floor division” rather than “integer division” though.