When I use the sort()
method on a list, then is affects the list permanently:
>>> numbers
[3, 1, 2]
>>> numbers.sort()
>>> numbers
[1, 2, 3]
>>>
On the other hand, for example, when I use the strip()
method on a string, then it doesn't affect the string permanently:
>>> string
' foo '
>>> string.strip()
'foo'
>>> string
' foo '
>>>
Why is this so? Does it depend on simply how the method is built?