incrementation operators?

Colin J. Williams cjw at connection.com
Mon Aug 14 11:40:27 EDT 2000


Thanks for sorting this out.  The discussion looks a little disconnected as
Thomas Wouters posting of Sun 12:10 PM did not make it to my news server.

Basically:  list += operand is equivalent to list.extend(operand)

If one wishes to append an element to a list, one must wrap the operand to
become a list with a single element.

Thus        list += [operand] is equivalent to list.append(operand)

Thanks

Colin W.

Peter Schneider-Kamp wrote:
> 
> Thomas Wouters wrote:
> >
> > On Sun, Aug 13, 2000 at 08:42:08PM -0400, Colin J. Williams wrote:
> > >
> > > Suppose one wishes to do a.append([5]).  It would appear that one would have to
> > > return to the existing syntax.
> 
> You'll have to do:
> 
> a += [[5]]
> 
> > "a += 3" isn't equivalent to a.append(3), it's equivalent to
> > 'a.extend(3)'. But you can write 'a.append(3)' as 'a.append([3])', and it's
> 
>                                                      ^^^^^^^^^^^^^
> I am sure you meant:                                 a.extend([3])
> 
> > solved :-) You might have missed that in my original posting: I did say you
> > could use augmented assignment in place of 'append' and 'extend', but my
> > example had that extra pair of brackets you need to make it work.
> 
> Yes.
> 
> Peter
> --
> Peter Schneider-Kamp          ++47-7388-7331
> Herman Krags veg 51-11        mailto:peter at schneider-kamp.de
> N-7050 Trondheim              http://schneider-kamp.de



More information about the Python-list mailing list