python isinf
时间: 2023-08-14 08:14:10 浏览: 113
python中的inf和nan
The `isinf()` function in Python is used to check if a given number is infinity. It returns `True` if the number is positive or negative infinity, and `False` otherwise.
Here's an example:
```python
import math
print(math.isinf(10)) # False
print(math.isinf(float('inf'))) # True
print(math.isinf(float('-inf'))) # True
```
In the above code, `math.isinf()` is used to check if a number is infinity or not. The first print statement returns `False` because 10 is not infinity. The second and third print statements return `True` because `float('inf')` and `float('-inf')` represent positive and negative infinity, respectively.
阅读全文