且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在Python中处理非常大的数字

更新时间:2023-02-19 22:54:20

Python支持"bignum"整数类型,该整数类型可以处理任意大数.在Python 2.5+中,此类型称为long,与int类型分开,但是解释器将自动使用更合适的那个.在Python 3.0+中,int类型已被完全删除.

Python supports a "bignum" integer type which can work with arbitrarily large numbers. In Python 2.5+, this type is called long and is separate from the int type, but the interpreter will automatically use whichever is more appropriate. In Python 3.0+, the int type has been dropped completely.

不过,这只是实现细节-只要您具有2.5或更高版本,就只需执行标准数学运算,并且任何超出32位数学界限的数字都将自动(透明地)转换为bignum.

That's just an implementation detail, though — as long as you have version 2.5 or better, just perform standard math operations and any number which exceeds the boundaries of 32-bit math will be automatically (and transparently) converted to a bignum.

您可以在 PEP 0237 中找到所有详细信息.

You can find all the gory details in PEP 0237.