整数的最大值和最小值 [英] Maximum and Minimum values for ints

查看:183
本文介绍了整数的最大值和最小值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找python中整数的最小值和最大值。例如,在Java中,我们有 Integer.MIN_VALUE Integer.MAX_VALUE 。在python中有这样的东西吗?

I am looking for minimum and maximum values for integers in python. For eg., in Java, we have Integer.MIN_VALUE and Integer.MAX_VALUE. Is there something like this in python?

推荐答案

Python 3



在Python 3中,这个问题不适用。普通的 int 类型是无限制的。

但是,您实际上可能正在寻找机器的 字数 。这在Python 3中仍可用作 sys.maxsize

However, you might actually be looking for the machine's word size. That's still available in Python 3 as sys.maxsize.

在Python 2中,普通 int的最大值值可用作 sys.maxint

In Python 2, the maximum value for plain int values is available as sys.maxint:

>>> sys.maxint
9223372036854775807

您可以使用计算最小值-sys.maxint - 1 如图所示 here

You can calculate the minimum value with -sys.maxint - 1 as shown here.

一旦超过此值,Python就会从普通整数切换为长整数。所以大部分时间你都不需要知道它。

Python seamlessly switches from plain to long integers once you exceed this value. So most of the time, you won't need to know it.

这篇关于整数的最大值和最小值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆