python.isnan_带有Python示例的math.isnan()方法

python.isnan

Python math.isnan()方法 (Python math.isnan() method)

math.isnan() method is a library method of math module, it is used to check whether a given number is "NaN" (Not a Number) or not, it accepts a number and returns True if given number is "NaN", else it returns False.

math.isnan()方法数学模块的库方法,用于检查给定数字是否为“ NaN” (不是数字),它接受一个数字,如果给定数字为“ NaN” ,则返回True ,否则返回False 。

Syntax of math.isnan() method:

math.isnan()方法的语法:

    math.isnan(n)

Parameter(s): n – a number that has to be checked whether it is "NaN" or not.

参数: n –必须检查是否为“ NaN”的数字。

Return value: bool – it returns a Boolean ("True" or "False") value.

返回值: bool –返回布尔值(“ True”或“ False”)。

Example:

例:

    Input:
    a = 10
    b = float('inf')
    c = float('nan')

    # function call
    print(math.isnan(a))
    print(math.isnan(b))
    print(math.isnan(c))

    Output:
    False
    False
    True

Python代码演示math.isnan()方法的示例 (Python code to demonstrate example of math.isnan() method)

# python code to demonstrate example of 
# math.isnan() method

# importing math module
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')))

Output

输出量

False
False
False
False
False
True


翻译自: https://www.includehelp.com/python/math-isnan-method-with-example.aspx

python.isnan

  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值