带有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 生日广州男生祝福语简短