integer and string compare, is that correct?
mail at hellmutweber.de
Mon Jan 11 01:44:30 CET 2010
thanks to all who answered.
I'm using Python 2.6.5 on my machine and consulted the corresponding
I do appreciate the modified definition of python 3, that seems much
Thanks for indicating.
Greetings from Munich in Winter
Am 10.01.2010 17:34, schrieb Nobody:
> Hellmut Weber wrote:
>>> being a causal python user (who likes the language quite a lot)
>>> it took me a while to realize the following:
>>> >>> max = '5'
>>> >>> n = 5
>>> >>> n>= max
>>> Section 5.9 Comparison describes this.
>>> Can someone give me examples of use cases
> Peter Otten wrote:
>> The use cases for an order that works across types like int and str are weak
>> to non-existent. Implementing it was considered a mistake and has been fixed
>> in Python 3:
>>>>> 5> "5"
>> Traceback (most recent call last):
>> File "<stdin>", line 1, in<module>
>> TypeError: unorderable types: int()> str()
> If you actually need to perform comparisons across types, you can rely
> upon the fact that tuple comparisons are non-strict and use e.g.:
> > a = 5
> > b = '5'
> > (type(a).__name__, a)< (type(b).__name__, b)
> > (type(a).__name__, a)> (type(b).__name__, b)
> The second elements will only be compared if the first elements are equal
> (i.e. the values have the same type).
Dr. Hellmut Weber mail at hellmutweber.de
Degenfeldstraße 2 tel +49-89-3081172
D-80803 München-Schwabing mobil +49-172-8450321
please: No DOCs, no PPTs. why: tinyurl.com/cbgq
More information about the Python-list