Neil Cerutti <[EMAIL PROTECTED]> wrote:
>  On 2007-02-14, Farshid Lashkari <[EMAIL PROTECTED]> wrote:
> > Szabolcs Nagy wrote:
> >>>>> L=[1]
> >>>>> L.extend((1,))
> >>>>> L
> >> [1, 1]
> >
> > Are list.extend() and list concatenation supposed to behave
> > differently? I always thought concatenation was just shorthand
> > for calling extend().
> 
>  They are different. list.extend() mutates the list, returning
>  None, while the + operator returns a new, concatenated list.
> 
>  += on the other hand works very similarly to list.extend().

It does make an inconsistency though...

>>> L=[1]
>>> L+=(1,)
>>> L
[1, 1]

Wheras

>>> L=[1]
>>> L=L+(1,)
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: can only concatenate list (not "tuple") to list
>>> 

Ie

    x += a

does not equal

    x = x + a

which it really should for all types of x and a

(That is the kind of statement about which I'm sure someone will post
a perfectly reasonable counterexample ;-)

-- 
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to