1.23 数值与字符串的比较¶

在 Python2 中,数字可以与字符串直接比较。结果是数值永远比字符串小。
>>> 100000000 < ""
True
>>> 100000000 < "hello"
True
但在 Python3 中,却不行。
>>> 100000000 < ""
TypeError: '<' not supported between instances of 'int' and 'str'
在 Python2 中,数字可以与字符串直接比较。结果是数值永远比字符串小。
>>> 100000000 < ""
True
>>> 100000000 < "hello"
True
但在 Python3 中,却不行。
>>> 100000000 < ""
TypeError: '<' not supported between instances of 'int' and 'str'