在Python中,什么是sys.maxsize? [英] In Python, what is `sys.maxsize`?

查看:5731
本文介绍了在Python中,什么是sys.maxsize?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我假设这个数字(2^63 - 1)是python可以处理或存储为变量的最大值.但是这些命令似乎运行良好:

I assumed that this number ( 2^63 - 1 ) was the maximum value python could handle, or store as a variable. But these commands seem to be working fine:

>>> sys.maxsize 9223372036854775807

>>> sys.maxsize 9223372036854775807

>>> a sys.maxsize + 1
>>> a 
9223372036854775808

那么,有什么意义吗?如果计算允许,Python可以处理任意数量的数字吗?

So is there any significance at all? Can Python handle arbitrarily large numbers, if computation resoruces permitt?

注意,这是我的版本的打印输出:

Note, here's the print-out of my version is:

>>> sys.version
3.5.2 |Anaconda custom (64-bit)| (default, Jul  5 2016, 11:41:13) [MSC v.1900 64 bit (AMD64)]'

推荐答案

Python可以处理计算中任意大的整数.任何太大而不能容纳64位的整数(或任何潜在的硬件限制)都在软件中处理.因此,Python 3没有sys.maxint常量.

Python can handle arbitrarily large integers in computation. Any integer too big to fit in 64 bits (or whatever the underlying hardware limit is) is handled in software. For that reason, Python 3 doesn't have a sys.maxint constant.

另一方面,值sys.maxsize报告平台的指针大小,并限制了Python数据结构(例如字符串和列表)的大小.

The value sys.maxsize, on the other hand, reports the platform's pointer size, and that limits the size of Python's data structures such as strings and lists.

这篇关于在Python中,什么是sys.maxsize?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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