Python string interning and substrings
Question: Does python create a completely new string (copying the contents) when you do
a substring operation like:

    
    
    new_string = my_old_string[foo:bar]
    

Or does it use interning to point to the old data ?

As a clarification, I'm curious if the underlying character buffer is shared
as it is in Java. I realize that strings are immutable and will always appear
to be a completely new string, and it would have to be an entirely new string
object.


Answer: You may also be interested in islice which does provide a view of the original
string

    
    
    >>> from sys import getrefcount
    >>> from itertools import islice
    >>> h="foobarbaz"
    >>> getrefcount(h)
    2
    >>> g=islice(h,3,6)
    >>> getrefcount(h)
    3
    >>> "".join(g)
    'bar'
    >>>
    

