Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #32738

Re: surprising += for lists

From Terry Reedy <tjreedy@udel.edu>
Subject Re: surprising += for lists
Date 2012-11-04 12:57 -0500
References <afn3i8Fn4j1U1@mid.uni-berlin.de> <50966379.3070801@davea.name>
Newsgroups comp.lang.python
Message-ID <mailman.3260.1352051847.27098.python-list@python.org> (permalink)

Show all headers | View raw


On 11/4/2012 7:45 AM, Dave Angel wrote:

> What I wonder about is why list's __add__  is so fussy.

Guido's reason is that it is not clear what the types of [1,2] + (3,4), 
(1,2) + [3,4], [] + range(4), range(2) + [3,4], etcetera should be. Such 
mixtures may be bugs. Seq.__add__ exists to implement '+'.

[].extend() will clearly be a list, and accepts any iterable.

I believe the same logic is used for set operations.

-- 
Terry Jan Reedy

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

surprising += for lists Ulrich Eckhardt <doomster@knuut.de> - 2012-11-04 12:57 +0100
  Re: surprising += for lists Alec Taylor <alec.taylor6@gmail.com> - 2012-11-04 23:06 +1100
  Re: surprising += for lists Dave Angel <d@davea.name> - 2012-11-04 07:45 -0500
  Re: surprising += for lists Terry Reedy <tjreedy@udel.edu> - 2012-11-04 12:57 -0500

csiph-web