How does Python 2 compare string and int? Why do lists compare as greater than numbers, and tuples greater than lists?

前端 未结 2 897
执笔经年
执笔经年 2020-11-21 04:44

The following snippet is annotated with the output (as seen on ideone.com):

print \"100\" < \"2\"      # True
print \"5\" > \"9\"        # False

print         


        
2条回答
  •  南旧
    南旧 (楼主)
    2020-11-21 04:58

    Strings are compared lexicographically, and dissimilar types are compared by the name of their type ("int" < "string"). 3.x fixes the second point by making them non-comparable.

提交回复
热议问题