get-a-cup-of-coffee slow

Niklas Frykholm r2d2 at mao.acc.umu.se
Fri Aug 10 01:05:46 EDT 2001


>    Grant> always an appended copy of the original?  (I guess I would hope
>    Grant> that in the case of a string "+=" operation, Python would leave a
>    Grant> little spare space at the end of the new string so multiple
>    Grant> appends would not have to make a copy with _each_ append.)
>
>Repeat the mantra: "strings are immutable, strings are immutable, strings
>are immutable". ;-)

But if the reference count is 1 they could be allowed to mutate internally
without destroying the immutable semantics. But is it worth it? You
would probably have been even more surprised if your program had run fast
when there was only one reference to the string and slow when there was
more than one.

// Niklas



More information about the Python-list mailing list