刚才我在this page上看到了一个小测验:
>>> x, y = ???
>>> min(x, y) == min(y, x)
False
示例答案是
x, y = {0}, {1}
从文档中我知道:
min(iterable[, key=func]) -> value
min(a, b, c, ...[, key=func]) -> valueWith a single iterable argument, return its smallest item.
With two or more arguments, return the smallest argument.
但为什么 min({0},{1})={0}
和 min({1},{0})={1}
?
我还尝试了其他几个:
min({0,2},1) # 1
min(1,{0,2}) # 1
min({1},[2,3]) # [2,3]
min([2,3],1) # 1
最佳答案
比较运算符 <
, <=
, >=
, 和 >
分别检查一个集合是否是另一个集合的严格子集、子集、超集或严格超集。
{0}
和 {1}
是 False
对于所有这些,因此结果取决于检查顺序和运算符(operator)。
关于python - 对 Python 最小测验感到困惑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33049388/