Python math.fmod()เมธอด
ตัวอย่าง
คืนค่าส่วนที่เหลือของ x/y:
# Import math Library
import math
# Return the remainder of x/y
print(math.fmod(20,
4))
print(math.fmod(20, 3))
print(math.fmod(15, 6))
print(math.fmod(-10, 3))
print(math.fmod(0, 0))
ความหมายและการใช้งาน
วิธี การmath.fmod()
คืนค่าส่วนที่เหลือ (โมดูโล) ของ x/y
ไวยากรณ์
math.fmod(x, y)
ค่าพารามิเตอร์
Parameter | Description |
---|---|
x | Required. A positive or negative number to divide |
y | Required. A positive or negative number to divide x with |
หมายเหตุ:ถ้าทั้ง x และ y = 0 จะส่งกลับ ValueError
หมายเหตุ:ถ้า y = 0 จะส่งกลับ ValueError
หมายเหตุ:ถ้า x หรือ y ไม่ใช่ตัวเลข จะส่งกลับ TypeError
รายละเอียดทางเทคนิค
คืนมูลค่า: | ค่า ที่float แสดงถึงส่วนที่เหลือของ x/y |
---|---|
เวอร์ชันหลาม: | 1.4 |