How can you copy (clone) a string?
Max Møller Rasmussen
maxm at normik.dk
Tue Oct 3 10:49:32 EDT 2000
That'll teach me never to mail untested code again....
Why then:
a = 'string1'
b = a[:]
b = b[:-1]
print a
>>string1
print b
>>string
print a
>>string1
Doesn't it make a copy when doing the slice??? Or is it first when the
string is changed that it does the actual copying???
-----Original Message-----
From: Fredrik Lundh [mailto:effbot at telia.com]
Sent: Tuesday, October 03, 2000 4:24 PM
To: python-list at python.org
Subject: Re: How can you copy (clone) a string?
Max Møller Rasmussen wrote:
> Just use slice:
>
> a = 'a'
> b = a[:]
>>> a = 'a'
>>> b = a[:]
>>> id(a)
7834944
>>> id(b)
7834944
>>> a is b
1
</F>
--
http://www.python.org/mailman/listinfo/python-list
More information about the Python-list
mailing list