On Wed, May 23, 2012 at 12:42 PM, Dave Angel wrote:
> On 05/23/2012 03:13 PM, Emile van Sebille wrote:
>> A design decision -- there's currently a mix of methods that return
>> themselves and not. Mostly is appears to me that mutables modify in
>> place without returning self and immutables retur
On 05/23/2012 03:13 PM, Emile van Sebille wrote:
> On 5/23/2012 5:23 AM 水静流深 said...
>> >>> 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)
>
> It could, but it doesn't.
>
>
>> ,what is the reason?
>
>
>
On 5/23/2012 5:23 AM 水静流深 said...
>>> 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)
It could, but it doesn't.
,what is the reason?
A design decision -- there's currently a mix of methods that return
themselves and not
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.a
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?
Because the append method returns None, not the object. It modifies the
object in place, and does not create any copy.
You can still write
s