Why doesn't deepcopy work on strings ?

Andrew Bennetts andrew-pythonlist at puzzling.org
Sun Feb 23 21:46:32 EST 2003


On Sun, Feb 23, 2003 at 06:16:20PM -0800, Tony C wrote:
> Why doesn't deepcopy() on a string make a deep copy of that string ?
> 
> Would someone explain this ..
> import copy
> s1="monty python"
> s2=copy.deepcopy(s1)
> id(s1)
> 19114192
> id(s2)
> 19114192 

Probably because it's unneccessary; strings are immutable.

-Andrew.






More information about the Python-list mailing list