String Methods Don't Change ID?

Rene Pijlman reageer.in at de.nieuwsgroep
Mon Jan 27 17:06:00 EST 2003


Kamilche:
>I'm looking the following example, which modifies a string, but the 
>ID doesn't change. Can anyone explain why the built-in string methods 
>don't modify the ID?
>
>>>> quest = 'what is your favorite color?'
>>>> id(quest)
>10988760
>>>> quest.capitalize()

This is an expression that produces a new string:

>'What is your favorite color?'

But in the mean time nothing has happened to quest. Neither to
it's value nor it's id.

>>>> id(quest)
>10988760

You see :-)

>>> quest = 'what is your favorite color?'
>>> id(quest)
9631048
>>> id(quest.capitalize())
9627920

-- 
René Pijlman

Wat wil jij leren?  http://www.leren.nl




More information about the Python-list mailing list