String Methods Don't Change ID?

Kamilche klachemin at home.com
Mon Jan 27 16:13:29 EST 2003


I am reading a book on Python, 'Core Python Programming.' They have
hammered home how when you change a string, or reassign it, the ID
changes.

But now, 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()
'What is your favorite color?'
>>> id(quest)
10988760
>>> quest.center(40)
'      what is your favorite color?      '
>>> id(quest)
10988760
>>>




More information about the Python-list mailing list