<dict>.setdefault()

Tino Lange tl_news at nexgo.de
Thu Jul 31 13:13:56 EDT 2003


On 31 Jul 2003 18:01:51 +0100, jjl at pobox.com (John J. Lee) wrote:

>Because that's the way Python always does function calls?

Of course. From the consistency point of view... perfectly right!
(I thought that maybe because these are very special low-level methods
for built-in types, it might be different....)

>Don't, then.  :-)  Use key in dict, or dict.has_key(key).

or the C-like style:
>>> a[3] = a.get(1) or b.setdefault(4,1)

Thanks!

Tino





More information about the Python-list mailing list