我一直在尝试找出如何表示最大整数,并且我已经阅读过使用 "sys.maxint"
。但是,在 Python 3 中,当我调用它时,我得到:
AttributeError: module 'object' has no attribute 'maxint'
原文由 Ci3 发布,翻译遵循 CC BY-SA 4.0 许可协议
我一直在尝试找出如何表示最大整数,并且我已经阅读过使用 "sys.maxint"
。但是,在 Python 3 中,当我调用它时,我得到:
AttributeError: module 'object' has no attribute 'maxint'
原文由 Ci3 发布,翻译遵循 CC BY-SA 4.0 许可协议
正如其他人所指出的,Python 3 的 int
没有最大尺寸,但是如果你只需要保证比其他任何东西都高的东西 int
值,那么你可以使用Infinity 的浮点值,您可以使用 float("inf")
获得。
在 Python 3.5 及更高版本中,您可以使用 math.inf
。
注意:根据 ely 的评论,这可能会影响代码的效率,因此它可能不是最佳解决方案。
原文由 mwfearnley 发布,翻译遵循 CC BY-SA 4.0 许可协议
4 回答4.4k 阅读✓ 已解决
4 回答3.8k 阅读✓ 已解决
1 回答3k 阅读✓ 已解决
3 回答2.1k 阅读✓ 已解决
1 回答4.5k 阅读✓ 已解决
1 回答3.8k 阅读✓ 已解决
1 回答2.8k 阅读✓ 已解决
http://docs.python.org/3.1/whatsnew/3.0.html#integers