开发者

How many can a tuple or list contain in Python?

How many items can contain tuple or list in python? What will be if it is 开发者_JS百科10 000?


import sys

print sys.maxsize
# prints some system-dependent number representing the maximum
# size most containers can hold.

Python sys module

I suspect on most platforms, sys.maxsize would return the same value as sys.maxint (which is guaranteed to be at least 2**31-1), but I doubt that's guaranteed.


You can try this yourself, interactively in the Python interpreter:

>>> tuple([0] * 10000)
(0, 0, 0, ... 0, 0)

where ... represents 9995 zeros.


If you mean what the maximum size of a tuple or list is, I assume that it is very large. Most likely you would run out of memory before hitting some limit. Someone else can add to this if they have specific knowledge of the indexing, possible 2.1 or 4.2 billion items in 32-bit and 8 or 16 sextillion in 64-bit.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜