'1' + 1 ==> True ???

Nicola Mingotti bla at libero.it
Wed Mar 17 23:24:26 EST 2004


On Thu, 18 Mar 2004 13:24:14 +1050, Ben Finney wrote:

> On Thu, 18 Mar 2004 03:45:56 +0100, Nicola Mingotti wrote:
>> I obtained this result : 
>> ------
>>>>> '1' > 1 
>> True
>> ------

> This should not be surprising; the values are different, so one will be
> "greater than" the other; but comparing them is not of much use.

Here i expect "Undefined Operation" or, if this is defined,
this means that '1' and 1 are comparable so, either 1 is 
seen as string or '1' is seen as a number . But ....

-----------------
>>>>> '1' + 1
>> TypeError 
>> -------

With this result i see that none of the two before mentioned possibility 
is possible because, in the first case i would expect ,as result, '11' and
, in the second, i would expect a number . I obtain TypeError so , i think
this is illogical .


> This, too, should not be surprising.  Adding a character and a number
> has no unambiguously correct meaning.
Also comparing a string and a character hasn't unambiguos meaning ,
has it ? 


>> -----------------------------
>>>>>'1'.__gt__.__doc__
>> 'x.__gt__(y) <==> x>y'
>> ----------------------------- 
> Showing that the comparison is pretty much what you'd expect.  Again,
> though, the result of comparing different types like character and
> integer isn't particularly useful.
>

Here i would expect the definition of '>' between strings . 
And the definition of '>' between 'chars' and 'integers' given
that a strange result has been returned .
I know python is growing and free so i don't expect that everything 
is documented or everything is correct and that is the reason i asked here.


> What behaviour did you expect?  Without knowing that it's hard to
> explain why the reality is different.

i imagined two possibility :

1) Like CommmonLisp (clisp implementation) -----> A Strinct Type Error 
[1]> (> "1" 1)
*** - >: "1" is not a REAL


2) Like C -----> Char is converted to int
#include<stdio.h>
int main(){
  printf("%i %i", '1' >  1 , '1' + 1 );
  return 0;
}
==> 1 50


Bye .

Excuse me again for mistakes or possible (but unwanted)
rude language . 





More information about the Python-list mailing list