Sometimes, we might be interested in integer division -- the division operation you might be familiar with from elementary school, where the result is always an integer (and there is a remainder, which you can always compute separately.) We use
// for that in Python.
Note that the result is always an
Side note: it's not the case that
int(a/b) == a//b, because of negative numbers.
It's not really worth bothering with the rules for dividing (by) negative integers -- just convert everything to its absolute value, and then add the sign if this situation comes up. We can, however, check the following:
a, b = -42, 5
(a//b) * b + (a % b)
Which is what we'd expect with positive numbers as well.