dictionary/hash and '1' versus 1
Piet van Oostrum
piet at cs.uu.nl
Tue Jan 8 03:48:39 EST 2008
>>>>> "Diez B. Roggisch" <deets at nospam.web.de> (DBR) wrote:
>DBR> So you can also do
>DBR> "" + some_object
>DBR> However,
>DBR> some_object + ""
>DBR> or
>DBR> 1 + ""
>DBR> don't work - the operator is only overloaded on the left argument.
There is no problem with 1+"" neither with new Integer(1)+"" in Java. Nor
any other object on the left hand side. The + operator is not tied to the
left hand side as in C++. if either side is a string and the other side has
a toString method it is OK. This is special-cased in the compiler. It is
defined in the language definition, not in the library definition.
--
Piet van Oostrum <piet at cs.uu.nl>
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email: piet at vanoostrum.org
More information about the Python-list
mailing list