Метод Python math.remainder()
Пример
Верните остаток x относительно y:
# Import math Library
import math
# Return the remainder of x/y
print (math.remainder(9, 2))
print (math.remainder(9,
3))
print
(math.remainder(18, 4))
Определение и использование
Метод math.remainder()
возвращает остаток x относительно y.
Синтаксис
math.remainder(x, y)
Значения параметров
Parameter | Description |
---|---|
x | Required. The number you want to divide. |
y | Required. The number you want to divide with. It must be a non-zero number, or a ValueError occurs. |
Технические детали
Возвращаемое значение: | Значение float , представляющее остаток |
---|---|
Версия Python: | 3,7 |
Дополнительные примеры
Пример
Вернуть остаток x/y:
print (math.remainder(23.5, 5))
print
(math.remainder(23, 5.5))
print (math.remainder(12.5, 2.5))
print
(math.remainder(12, 2))