get a copy of a string leaving original intact

Fredrik Lundh fredrik at pythonware.com
Sat Oct 22 03:40:12 EDT 2005


"Bell, Kevin" wrote:

> I ended up slicing my string into a new one, rather than trying to have
> a copy of the string to alter in one case, or leave intact in another
> case.

given that you cannot modify strings in place in Python, that comment
probably doesn't match what your code really did...

("s = f" doesn't copy the string, it just binds a new name to the
existing string object.  "s = s.replace" doesn't modify that object;
it creates a new one, and binds the same name to that one in-
stead)

</F>






More information about the Python-list mailing list