Comparing integers in Python

Possible duplicate:
How does Python compare string and int?

I did some comparison in Python. I was surprised to see that I can compare a string with an integer. then I made an identifier and found out that in fact the identifier for the string is greater than the id for int, and I thought that the reason I get this output.

In [19]: 'a' < 3
Out[19]: False

In [20]: 'a'>3
Out[20]: True

In [17]: id('a')
Out[17]: 140414909035824

In [18]: id(3)
Out[18]: 23119752

Please confirm that I am interpreting this behavior correctly (comparing Python with id level).

+3
source share
1 answer

Comparison of the transverse type Python 2.x - a historical accident. From the documentation :

(...) objects of different types are always compared unevenly and ordered sequentially, but arbitrarily

Python 3.x - .

+5

All Articles