Python math.isfinite()เมธอด
ตัวอย่าง
ตรวจสอบว่ามีค่าจำกัดหรือไม่:
# Import math Library
import math
# Check whether the values are
finite or not
print(math.isfinite(2000))
print(math.isfinite(-45.34))
print(math.isfinite(+45.34))
print(math.isfinite(math.inf))
print(math.isfinite(float("nan")))
print(math.isfinite(float("inf")))
print(math.isfinite(float("-inf")))
print(math.isfinite(-math.inf))
print(math.isfinite(0.0))
ความหมายและการใช้งาน
วิธี การmath.isfinite()
ตรวจสอบว่าจำนวนจำกัดหรือไม่
เมธอดนี้คืนค่า True ถ้าตัวเลขที่ระบุเป็นจำนวนจำกัด มิฉะนั้นจะคืนค่า False
ไวยากรณ์
math.isfinite(x)
ค่าพารามิเตอร์
Parameter | Description |
---|---|
x | Required. The value to check. Must be a number (float/integer/infinite/NaN/finite) |
รายละเอียดทางเทคนิค
คืนมูลค่า: | ค่า เป็นbool จริงถ้าxเป็นจำนวนจำกัด เท็จถ้าxเป็นอนันต์หรือเป็น NaN |
---|---|
เวอร์ชันหลาม: | ใหม่ใน Python 3.2 |