Python math.remainder() 方法
示例
返回 x 對 y 的餘數
# 匯入 math 庫
import math
# 返回 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)
引數值
引數 | 描述 |
---|---|
x | 必需。要被除的數字。 |
y | 必需。要用來除的數字。它必須是非零數字,否則會發生 ValueError。 |
技術詳情
返回值 | 一個 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))
自己動手試一試 »