Why is int(50)<str(5) in python 2.x?

前端 未结 4 523
南笙
南笙 2021-01-13 00:32

In python 3, int(50)<\'2\' causes a TypeError, and well it should. In python 2.x, however, int(50)<\'2\' returns True

4条回答
  •  無奈伤痛
    2021-01-13 01:01

    (And who thought it was a good idea to allow this to begin with???)

    I can imagine that the reason might be to allow object from different types to be stored in tree-like structures, which use comparisons internally.

提交回复
热议问题