append on lists

Grant Edwards grante at visi.com
Tue Sep 16 09:55:56 EDT 2008


On 2008-09-16, Armin <a at nospam.org> wrote:
> Alex Marandon wrote:
>> Armin wrote:
>>> Duncan Booth wrote:
>>>
>>> The semantic of [1,2,3,4,7].append(c) and [1,2,3,4,7] + c
>>> (with c = [8,9]) is identical,
>> 
>> No it's not, + doesn't alter its operands.
>> 
>>  >>> a = 1
>>  >>> b = 2
>>  >>> a + b
>> 3
>
> That's not the point :)
>
> What's the value of 1.add(b)?  None? Or 3 ??

>>> a = 1
>>> b = 2
>>> 1.add(b)
  File "<stdin>", line 1
    1.add(b)
        ^
SyntaxError: invalid syntax

> (if add works in the same way as append)

It doesn't.

> a + b doesn't change a,b ... but a.add(b) -> a=3

WTH are you talking about?

-- 
Grant Edwards                   grante             Yow! I just got my PRINCE
                                  at               bumper sticker ... But now
                               visi.com            I can't remember WHO he
                                                   is ...



More information about the Python-list mailing list