带有Python示例的math.isnan()方法
Pythonmath.isnan()方法
math.isnan()方法是数学模块的库方法,用于检查给定数字是否为“NaN”(不是数字),它接受一个数字,如果给定数字为“NaN”,则返回True,否则返回False。
它的语法math.isnan()方法:
math.isnan(n)
Parameter(s):n–必须检查是否为“NaN”的数字。
返回值:bool–返回布尔值(“True”或“False”)。
示例
Input:
a = 10
b = float('inf')
c = float('nan')
#函数调用
print(math.isnan(a))
print(math.isnan(b))
print(math.isnan(c))
Output:
False
False
TruePython代码演示示例math.isnan()方法
#python代码演示示例
# math.isnan() method
#导入数学模块
import math
# math.isnan() method test on finite value
print(math.isnan(10))
print(math.isnan(0))
print(math.isnan(10.23))
print(math.isnan(0.0))
# math.isnan() method test on infinite and NaN value
print(math.isnan(float('inf')))
print(math.isnan(float('-inf')))
print(math.isnan(float('nan')))输出结果
False False False False False True
热门推荐
10 对患者生日祝福语简短
11 结婚祝福语简短装备
12 周岁祝福语学生文案简短
13 订婚领证祝福语简短精辟
14 导师获奖祝福语大全简短
15 新婚购房祝福语简短精辟
16 牛年祝福语简短的爱人
17 送芒果的祝福语简短
18 送给学长毕业祝福语简短