String Methods Don't Change ID?

Erik Max Francis max at alcyone.com
Tue Jan 28 02:01:46 EST 2003


Kamilche wrote:

> Calling a method on a string SEEMS like it should modify the original,
> not create a new one, but I guess strings are 'special' all the way
> around.  To me, it's kinda like saying 'person.logon(logonid,
> password)' creating a new person object and logging them on, while
> leaving the original person untouched.

In many languages where fundamental types are represented with objects,
the objects for some of those types are immutable for efficiency
purposes.  Doing it this way means that you can make a lot of
optimizations that simply would not be possible otherwise, since you'd
have to take into account the possibility of the value in the object
changing underneath you.  Java's string class (java.lang.String), for
instance, is immutable, like Python's.

-- 
 Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
 __ San Jose, CA, USA / 37 20 N 121 53 W / &tSftDotIotE
/  \ Peace with a cudgel in hand is war.
\__/ (a Portugese proverb)
    Blackgirl International / http://www.blackgirl.org/
 The Internet resource for black women.




More information about the Python-list mailing list