string slicing

Ishwor ishwor.gurung at gmail.com
Sun Dec 5 09:54:06 EST 2004


On Sun, 05 Dec 2004 09:44:13 -0500, Kent Johnson <kent3737 at yahoo.com> wrote:

[snip]

> 
> This behaviour is due to the way strings are handled. In some cases strings are 'interned' which
> lets the interpreter keep only a single copy of a string. If you try it with a list you get a
> different result:
> 
> >>> s=list('hello')
> >>> s
> ['h', 'e', 'l', 'l', 'o']
> >>> m=s[:]
> >>> m
> ['h', 'e', 'l', 'l', 'o']
> >>> m is s
> False
> 
> Kent

Thanx Kent.  so for lists Python doesn't keep the same object in the
cache??? So in that case it is not interned & hence any objects
created will **point** to seperate area in memory as seen by your
>>> m is s  #( for lists) 
>>> False

Thanx again :)
[snip]

-- 
cheers,
Ishwor Gurung



More information about the Python-list mailing list