string copying

Peter Hansen peter at engcorp.com
Fri Mar 29 18:16:27 EST 2002


Jeff Shannon wrote:
> 
> In article <AZ3xhtAObNp8EwwK at jessikat.fsnet.co.uk>,
> robin at jessikat.fsnet.co.uk says...
> > Is there some special reason why python inhibits string copying. I
> > suppose there's some attempt being made to make these constants. To make
> > differing versions of 'abc' one has to resort to silliness like 'ab'+'c'
> 
> 1) Strings are immutable.  This implies that there is zero
> practical difference between two references to two separate
> string objects of identical value, and two references to the same
> string object.

The only one I've been able to think of is the surprisingly
common situation of trying to consume vast quantities of memory
quickly by something like:

a = [0] * 1000000
for i in xrange(1000000):
    a[i] = 'bigstringsuckinguplotsofmemory'

If nothing else, this confuses newbies for a while...



More information about the Python-list mailing list