Skip to content

if-stmt-min-max (PLR1730)#

Derived from the Pylint linter.

Fix is sometimes available.

This rule is unstable and in preview. The --preview flag is required for use.

What it does#

Checks for if statements that can be replaced with min() or max() calls.

Why is this bad?#

An if statement that selects the lesser or greater of two sub-expressions can be replaced with a min() or max() call respectively. When possible, prefer min() and max(), as they're more concise and readable than the equivalent if statements.


if score > highest_score:
    highest_score = score

Use instead:

highest_score = max(highest_score, score)