On Mon, Oct 12, 2009 at 4:44 AM, Nadav Chernin <nada...@qualisystems.com> wrote: > > Chris Withers wrote: > > ...becauase you were looking for: > > reversed([1,2,3,4]) > > OK, but my question is generic. Why when I use object's function that > changed values of the object, I can't to get value of it on the fly > without writing additional code? > >>>> a=[1,3,2,4] >>>> a.sort() >>>> a.reverse() >>>> a > [4, 3, 2, 1] > > Why I can't a==[1,3,2,4].sort().reverse() ?
That's just the way it is with list objects. Note that string objects do work that way: In [1]: "FOO".lower().replace('o', 'a') Out[1]: 'faa' But this is because string objects are immutable in python, so their methods must return new strings. Bottom line: read the documentation. (In the python interpreter you can use the built-in function help() on any object or function or method to get information on it.) HTH, ~Simon -- http://mail.python.org/mailman/listinfo/python-list