if-expr-min-max (FURB136) 派生自 refurb 代码检查工具。 有时提供修复。 作用 检查可以被 min() 或 max() 调用替换的 if 表达式。 为什么这不好? 选择两个子表达式中较小或较大值的 if 表达式可以分别用 min() 或 max() 调用替换。如果可能,请优先使用 min() 和 max(),因为它们比等效的 if 表达式更简洁易读。 示例 highest_score = score1 if score1 > score2 else score2 建议改为 highest_score = max(score2, score1) 参考 Python 文档: min Python 文档: max