【发布时间】:2015-03-08 09:31:34
【问题描述】:
我已经搜索过了,似乎没有人有这个特定的问题。为什么 Python 让我将列表与整数进行比较?例如,
[]
评估为假
和
[] > 10
评估为真
这些操作不是定义不明确吗,Python 不应该为这些操作抛出异常吗?
【问题讨论】:
-
这基本上是 Python 2 中的设计缺陷。从 Python 3 开始,禁止像这样定义不明确的比较:docs.python.org/3.0/whatsnew/3.0.html#ordering-comparisons
标签: python strong-typing typing dynamic-typing