Python – cmath.isinf()函数
cMath 模块包含许多用于复数数学运算的函数。 cmath.isinf()函数用于检查值是正无穷还是负无穷。此函数中传递的值可以是int、float和复数。
Syntax: cmath.isinf(x)
Parameter:This method accepts the following parameters.
- x :This parameter is the value to check for infinity.
Returns:This method returns a Boolean value.
下面的例子说明了上述函数的使用:
示例 #1:
Python3
# Python code to implement
# the isinf()function
# importing "cmath"
# for mathematical operations
import cmath
# using cmath.isinf() method
val = cmath.isinf(1 + 2j)
print(val)
Python3
# Python code to implement
# the isinf()function
# importing "cmath"
# for mathematical operations
import cmath
# using cmath.isinf() method
val = cmath.isinf(complex(1 + float('inf')))
print(val)
输出:
False
示例 2:
Python3
# Python code to implement
# the isinf()function
# importing "cmath"
# for mathematical operations
import cmath
# using cmath.isinf() method
val = cmath.isinf(complex(1 + float('inf')))
print(val)
输出:
True