intern'ed strings and deepcopy()

Skip Montanaro skip at pobox.com
Fri Apr 11 21:04:09 CEST 2003


    fp> I can't seem to find the exact description between these two in the
    fp> Library Reference - so am I correct in assuming that deepcopy() will
    fp> not actually duplicate an intern'ed string?

Strings (interned or not) are immutable, so there's never a need to copy
them:

    >>> s = "abc def ghi jkl"
    >>> id(s)
    9251080
    >>> id(copy.deepcopy(s))
    9251080

    >>> t = intern("abc")
    >>> id(t)
    11982528
    >>> id(copy.deepcopy(t))
    11982528

Skip





More information about the Python-list mailing list