Home>Article>Backend Development> How to get the remainder in python

How to get the remainder in python

藏色散人
藏色散人 Original
2019-07-01 09:35:26 30357browse

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.

How to get the remainder in python

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn