MY REAL QUESTION: Why do stringobjects not have methods? We have
listobjects that have their own methods so that I can say:
[1, 3, 2].sort()
But if I want to do similar operations on stringobjects I have to
import string or strop and pass my strings through these functions.
Why? Why can't I just say:
message = 'get down get'.append(' funky')
I understand that strings are immutable, but is that necessarily the
right thing? I'll often tack things on to the end of a string with:
string = string + char
and this goes and creates a new string object that is the combination
of the first string and the new char. Wouldn't it be more efficient
to simply add the char onto the end of the original string? I
understand I'm poking at a pedagogical hornet's nest here with the
mutable vs. immutable argument (see the socratic discussion concerning
lists and tuples, right?) but could someone please explain it to me
AND ANOTHER THING: Why do the listobject methods always return None?
It would be more useful if they returned the listobject that resulted
from the method call. That way I could chain operations together like
mylist = [1, 2, 3].reverse().append(0).reverse()
and mylist would == [0, 1, 2, 3]. Is there a reason this would be a
bad thing? the methods have to return SOMETHING, right? How about
something a little more useful than None, eh?