dictionary initialization
Peter Hansen
peter at engcorp.com
Thu Nov 25 16:37:27 EST 2004
Weiguang Shi wrote:
> In article <lIydnVF-WvXK3TvcRVn-jA at rogers.com>, Dan Perl wrote:
>>That would not be justified in python. The type of b[1] is
>>undetermined until initialization and I don't see why it should be
>>an int by default.
>
> In my example, it was b[1]+=1. "+=1" should at least tell Python two
> things: this is an add operation and one of the operands is an
> integer.
Why would it tell Python that?
>>> b = {1: 2.5}
>>> b[1] += 1
>>> b
{1: 3.5}
So at this point, it can clearly be either an integer or
a float. Doubtless it could also be an object which
overloads the += operator with integer arguments, though
what it might actually do is anyone's guess.
-Peter
More information about the Python-list
mailing list