Appending to []
Kiuhnm
kiuhnm03.4t.yahoo.it
Sat Apr 21 10:31:49 EDT 2012
On 4/21/2012 14:48, Bernd Nawothnig wrote:
> On 2012-04-20, Rotwang wrote:
>> since a method doesn't assign the value it returns to the instance on
>> which it is called; what it does to the instance and what it returns are
>> two completely different things.
>
> Returning a None-value is pretty useless. Why not returning self, which would be
> the resulting list in this case? Returning self would make the
> language a little bit more functional, without any drawback.
>
> Then nested calls like
>
> a = [].append('x').append('y').append('z')
You just answered to your own question: append returns None so that
people can't use it the way you did.
You make the reader believe that you're adhering to the functional
paradigm whereas 'append' has actually side effects!
Moreover, you use an assignment just to reinforce this wrong belief.
Kiuhnm
More information about the Python-list
mailing list