Home>Article>Backend Development> How to get the remainder in python
How to get the remainder in python?
In Python, the calculation formula for remainder is no different from other languages: remainder r=a-n*[a//n], where a is the dividend and n is the divisor.
This will involve the dividend or the divisor being a negative number. But as long as you know the principles, you can solve it.
If the divisor is a negative number, the result will also be a negative number.
Note:
The definition of modulo operation: a % b = a - n*b, n is not greater than a /b The largest integer.
% operator: modulus - returns the remainder of division
//Operator: rounding division - returns the integer part of the quotient (rounded down)
Related recommendations : "Python Tutorial"
The above is the detailed content of How to get the remainder in python. For more information, please follow other related articles on the PHP Chinese website!