Why doesn't deepcopy work on strings ?

Alex Martelli aleax at aleax.it
Mon Feb 24 05:08:11 EST 2003


Gerrit Holl wrote:
   ...
> Try: s1[:] to copy a string.

>>> x='ciao'
>>> y=x[:]
>>> x is y
True
>>>

try as much as you will, Python is always allowed to optimize
away copies when immutable objects are concerned, and will do
so whenever its current implementation is clever enough;-).


Alex





More information about the Python-list mailing list