Beginner: How to copy a string?

Peter Hansen peter at engcorp.com
Thu Mar 27 19:45:28 EST 2003


dbrown2 at yahoo.com wrote:

> I just want to make a copy of a string, say s='abc'.  I understand
> that python is not like some other languages and '=' just assigns a
> name to an existing object and does not copy the object.  

Why would you want to do that?  Strings are *immutable*.  They 
*cannot* be modified.  Therefore a copy is, or at least should be,
completely useless.  If you are relying on the id() of the string
and need them to be different, even though the content of the 
strings is the same, you probably have a design flaw and if you
explain what you are trying to do we can probably find a better
way to accomplish it.

-Peter




More information about the Python-list mailing list