dictionary initialization

Jp Calderone exarkun at divmod.com
Fri Nov 26 16:52:39 EST 2004


On Fri, 26 Nov 2004 16:34:42 -0500, "Terry Reedy" <tjreedy at udel.edu> wrote:
>
> "BJ�rn Lindqvist" <bjourne at gmail.com> wrote in message 
> news:740c3aec04112613043a0b0d2b at mail.gmail.com...
> > >>> del x
> > >>> x *= 5
> 
> > Maybe Python can't guess it, but *I* can guess, with 99% certainity,
> > that the user wants x to be 0. :)
> 
> However, it is 'obvious' to me that the 'proper' initialization is 1 and 
> the intended result should be 5.  Or that the programmer forgot something 
> and that the proper response is to raise an error, as Python does.  Wanting 
> 5 * undisclosed something to be 0 strikes me as unlikely and a distant 
> third since x = 0 is much easier to say.
> 
> Also: 'x op= y' is defined as being semantically equal to 'x = x op y' 
> except for the single rather than double evaluation of x.  

  No it isn't.  It makes no difference in this case, but in others it is relevant:


    x = y = []
    x += [1]

  vs

    x = y = []
    x = x + [1]

  Jp



More information about the Python-list mailing list