learnpython.org - an online interactive Python tutorial

Tim Chase python.list at tim.thechases.com
Sat Apr 23 13:25:24 EDT 2011


On 04/23/2011 11:51 AM, Dotan Cohen wrote:
> harrismh777<harrismh777 at charter.net>  wrote:
>> If an operation like (+) is used to add  1 + '1' then the
>> string should be converted to int and the addition should
>> take place, returning a reference to object int (2).
>
> No, the int 1 should be cast to a string, and the result
> should be the string '11'.

Oh, come on...clearly if you're adding mixed types, there's 
significance to the difference, so the result should obviously be 
the complex number

   (1+1j)

Or maybe it should be the tuple

   (1,1)

Or did I mean the list

  [1,1]

It's all so obvious...  :)

I didn't mind the auto-promotion (as much) in VB6 when I had an 
explicit concat operator

   1 & "1"   ' returns "11"

vs

   1 + "1"   ' returns 2

-tkc







More information about the Python-list mailing list