How can you copy (clone) a string?

Fredrik Lundh effbot at telia.com
Tue Oct 3 11:29:23 EDT 2000


Peter Schneider-Kamp wrote:
> If you know it is not empty:
> 
> >>> a = "abcd"
> >>> b = a[:1] + a[1:]
> >>> id(a)
> 21765696
> >>> id(b)
> 21763648
> >>> a is b
> 0
> >>> a == b
> 1 

>>> a = "a" # not empty
>>> b = a[:1] + a[1:]
>>> id(a)
7834944
>>> id(b)
7834944
>>> a is b
1
>>> a == b
1

</F>




More information about the Python-list mailing list