What is the maximum size of variable in python?

See sys.maxsize: http://docs.python.org/library/sys.html

The largest positive integer supported by the platform’s Py_ssize_t type, and thus the maximum size lists, strings, dicts, and many other containers can have.

On my MacBook Pro with a 64-bit build of CPython, it's quite sensibly 263-1 bytes:

>>> import sys
>>> sys.maxsize
9223372036854775807
>>> 

While on my 32-bit Linux box, it's 2^31-1:

>>> import sys
>>> sys.maxsize

>>> 

In practice, of course, you're unlikely to be able to actually make use of objects this large, but you can expect to run into serious practical problems (like, say, being out of memory or taking forever to load/save objects from storage) before you hit the theoretical limits.

Python allow you to only take care about variable name and ignore it's
size because pyhton dynamicly allocate it
so what's the limit in the allocated size in the memory

Dec 31 '07 #1

En Mon, 31 Dec 2007 15:40:31 -0200, هنداوى <3D********@gmail.comescribi�:

Python allow you to only take care about variable name and ignore it's
size because pyhton dynamicly allocate it
so what's the limit in the allocated size in the memory

As big as would fit on available memory.

--
Gabriel Genellina

Dec 31 '07 #2

On Dec 31, 11:26�*am, "James Matthews" <:

However some Debuggers will not show you variable's that are too big!

On Dec 31, 2007 7:38 PM, Gabriel Genellina <:

En Mon, 31 Dec 2007 15:40:31 -0200, هنداوى<>
escribi�:
Python allow you to only take care about variable name and ignore it's
size because pyhton dynamicly allocate it
so what's the limit in the allocated size in the memory
As big as would fit on available memory.

Is that mean that i can deal with files with size more than 2GB only
if the available memory allow

Dec 31 '07 #3

On Dec 31, 4:05�*pm, "هنداوى"

On Dec 31, 11:26�*am, "James Matthews" <:
However some Debuggers will not show you variable's that are too big!
On Dec 31, 2007 7:38 PM, Gabriel Genellina <:
En Mon, 31 Dec 2007 15:40:31 -0200, هنداوى <>
escribi�:
Python allow you to only take care about variable name and ignore it's
size because pyhton dynamicly allocate it
so what's the limit in the allocated size in the memory
As big as would fit on available memory.

Is that mean that i can deal with files with size more than 2GB only
if the available memory allow

No, files can be often be dealt with in manageable
chunks. Instead of reading the entire file into
memory, often it suffices to read in a line at a
time.

Dec 31 '07 #4

En Mon, 31 Dec 2007 20:05:41 -0200, هنداوى <3D********@gmail.comescribi�:

On Dec 31, 11:26�*am, "James Matthews" <:
>However some Debuggers will not show you variable's that are too big!

On Dec 31, 2007 7:38 PM, Gabriel Genellina <>
wrote:

En Mon, 31 Dec 2007 15:40:31 -0200, هنداوى <>
escribi�:
Python allow you to only take care about variable name and ignore
it's
size because pyhton dynamicly allocate it
so what's the limit in the allocated size in the memory
As big as would fit on available memory.

Is that mean that i can deal with files with size more than 2GB only
if the available memory allow

To be more precise, that depends on the OS. On Windows there is a limit of
2GB adressable memory per process (this is unrelated to the amount of
physical memory). You may increase that limit to 3GB. I think Python can
handle all the memory the OS is able to provide.
But do you actually have to keep the whole file in memory?

--
Gabriel Genellina

Dec 31 '07 #5

In the darkest hour on Mon, 31 Dec 2007 20:53:28 -0200,
Gabriel Genellina

>Is that mean that i can deal with files with size more than 2GB only
if the available memory allow

To be more precise, that depends on the OS. On Windows there is a limit of
2GB adressable memory per process (this is unrelated to the amount of
physical memory).

That's the 32bit Windows limit only (afaik).

--
[ Artur M. Piwko : Pipen : AMP29-RIPE : RLU:100918 : From == Trap! : SIG:240B ]
[ 16:51:04 user up 11576 days, 4:46, 1 user, load average: 0.97, 0.71, 0.01 ]

No wonder people are so horrible when they start life as children. -- K. Amis

Jan 4 '08 #6

This discussion thread is closed

Replies have been disabled for this discussion.

How big can a variable be?

How Big Is a Variable. As big as is needed and no more. The smallest a variable can be is one bit and the largest is millions of bytes. Current processors handle data in chunks of 4 or 8 bytes at a time (32 and 64 bit CPUs), so the bigger the variable, the longer it will take to read or write it.

How large of a number will a variable hold in Python?

Integers and Longs For whole numbers, Python offers two data types: integers and long integers. An integer's variable is referred to as int and is stored using at least 32 bits. This will likely meet most of your needs because it can hold any number from around negative 2 billion to positive 2 billion.

Can variables have unlimited length in Python?

Identifiers are unlimited in length. Case is significant. In other words, variable names can be of any length and can use any upper case or lowercase letters, the underscore, and the digits 0-9. However, variables names cannot begin with a digit.

What's the largest number Python can handle?

It's usually 2^31 - 1 on a 32-bit platform and 2^63 - 1 on a 64-bit platform.