> ## Documentation Index
> Fetch the complete documentation index at: https://docs.sourcery.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Max/min Default

#### Sourcery refactoring id: `max-min-default`

#### Description

Use max/min default argument instead of if statement

#### Before

```python
a = [1, 2, 3]
if a:
    b = max(a)
else:
    b = 0
```

#### After

```python
a = [1, 2, 3]
b = max(a, default=0)
```

#### Explanation

When using `max`/`min` over an iterable we often want to provide a default
value.

Instead of setting this using an `if` statement we can use the `default` keyword
argument of
[max](https://docs.python.org/3/library/functions.html#max)/[min](https://docs.python.org/3/library/functions.html#min)
directly. This makes the intent of the code much clearer and makes it much
easier to read.
