如何在Python中表示一个无限数? [英] How can I represent an infinite number in Python?
本文介绍了如何在Python中表示一个无限数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在python中表示一个无限数?无论您在程序中输入哪个数字,都不能大于此无穷大表示形式.
How can I represent an infinite number in python? No matter which number you enter in the program, no number should be greater than this representation of infinity.
推荐答案
在Python中,您可以执行以下操作:
In Python, you can do:
test = float("inf")
在Python 3.5中,您可以执行以下操作:
In Python 3.5, you can do:
import math
test = math.inf
然后:
test > 1
test > 10000
test > x
将永远是真实的.当然,除非指出,否则x也是无穷大或"nan"(不是数字").
Will always be true. Unless of course, as pointed out, x is also infinity or "nan" ("not a number").
另外(仅Python 2.x),与Ellipsis
相比,float(inf)
较小,例如:
Additionally (Python 2.x ONLY), in a comparison to Ellipsis
, float(inf)
is lesser, e.g:
float('inf') < Ellipsis
将返回true.
这篇关于如何在Python中表示一个无限数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文