dictionary initialization

Terry Reedy tjreedy at udel.edu
Fri Nov 26 22:34:42 CET 2004


"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.  Therefore, if 
the latter raises an error for unbound x, so should the former.

Terry J. Reedy






More information about the Python-list mailing list