math.inf常数,带Python示例

本文介绍了Python中的math.inf常量,它是math模块的一部分,表示正无穷大。从Python 3.5开始可用。示例代码展示了如何使用math.inf及其负值。同时还提到了相关数学函数如math.isfinite()、math.isinf()等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Python math.inf常数 (Python math.inf constant)

math.inf constant is a predefined constant, which is defined in the math module, it returns a floating-point positive infinity (which is equivalent to float('inf')).

math.inf常量是在math模块中定义的预定义常量,它返回浮点正无穷大(等效于float('inf')) 。

-math.inf can be used to find floating-point negative infinity (which is equivalent to float('-inf')).

-math.inf可用于找到浮点负无穷大(等效于float('-inf')) 。

Note: math.inf constant is available from Python 3.5

注意: math.inf常数可从Python 3.5获得

Syntax of math.inf constant:

math.inf常数的语法:

    math.inf

Return value: float – that is the value of positive infinity.

返回值: float-这是正无穷大的值。

Example:

例:

    Input:
    print(math.inf)

    Output:
    inf

Python代码演示math.inf常量示例 (Python code to demonstrate example of math.inf constant)

# python code to demonstrate example of 
# math.inf constant

# importing math module
import math 

# printing value of infinity
print("value of positive infinity = ", math.inf)
print("value of negative infinity = ", -math.inf)

Output

输出量

value of positive infinity = inf
value of negative infinity = -inf

Recommended posts

推荐的帖子

Reference: Python math library

参考: Python数学库

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值