Python TypeError: '<' not supported between instances of 'int' and 'list'

Python TypeError: '<' not supported between instances of 'int' and 'list'

我想将一个值与列表进行比较,如果所有值都为 True,则 return 为 True。如果任何值为 False,则 return False。 例如:

all(3 < [3,4,5])

应该return错误。

all(3 < [4,5])

应该return正确。但是,我收到此错误:

TypeError: '<' not supported between instances of 'int' and 'list'

运行:

3 < all([4,5])

但没有得出正确答案,因为 3 大于 [True, True]。如果这是重复的,我深表歉意,但在我在 SO 上发现的关于此错误的 6 个示例中,none 个示例回答了我的问题。奇怪的是,我觉得我过去已经成功地使用过它,没有任何问题。我在 Macbook 上 运行 Python 3.7.3。

all(3 < i for i in [4, 5])

all 作用于布尔序列;它不会分布在任意参数上。在发布之前搜索 tutorial 通常是个好主意。