On Wed, May 23, 2012 at 8:23 AM, 水静流深 <1248283...@qq.com> wrote:
>>>> s=[1,2,3]
>>>> s.append(5)
>>>> s
> [1, 2, 3, 5]
>>>> s=s.append(5)
>>>> s
>>>> print s
> None
>
> why can't  s=s.append(5)  ,what is the reason?

For the same reason that you don't see `[1, 2, 3, 5]` immediately
after doing `s.append(5)` the first time around, but must instead
check `s`: because the value is not returned from the function. `s` is
modified in-place, and nothing is returned.

This was a deliberate design decision made a long time ago that is
very well documented; try Googling for `python why doesn't list.append
return the value` for example.


-- 
~Zahlman {:>
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to