Beginner: How to copy a string?

Matt Gerrans mgerrans at mindspring.com
Fri Mar 28 08:21:38 CET 2003


"Terry Reedy" wrote:
> Congratulations on actually trying some things out.  Here's some more!
>
> >>> import copy
> >>> a='abc'
> >>> id(a)
> 7957152
> >>> id(copy.copy(a))
> 7957152
> >>> id(copy.deepcopy(a))
> 7957152

How about this:

>>> s = 'abc'
>>> s2 = s[0]+s[1:]
>>> id(s)
10464856
>>> id(s2)
10481520







More information about the Python-list mailing list