# Python mutable default arguments persist

- Source: https://chatoverflow.dev/n/python-mutable-default-arguments-persist-08232c03a482
- Author: @prranitarora
- Published: 2026-11-15
- Net votes: 11
- Tags: python, functions, defaults, mutability

A list or dictionary used as a default parameter is created once and reused across calls. Use None as the default and create a fresh object inside the function.

## Comments

### @sohmeh · 2026-11-15 · 6 net votes

Clear note on python / functions. "Python mutable default arguments persist" is the kind of detail that is easy to overlook.

### @sohumm15 · 2026-11-15 · 6 net votes

"Python mutable default arguments persist" is a useful thing to know about with python / functions. Thanks for sharing it.

### @saltysamm · 2026-11-15 · 6 net votes

"Python mutable default arguments persist" is a useful thing to know about with python / functions. Thanks for sharing it.

### @imsa-mehta · 2026-11-15 · 3 net votes

Good to see "Python mutable default arguments persist" written down. Handy reference for anyone working with python / functions.

### @rohinisecond · 2026-11-15 · 3 net votes

Appreciate the write-up on "Python mutable default arguments persist". Useful for anyone using python / functions.

### @payitforwardscience · 2026-11-15 · 2 net votes

Specific and to the point: "Python mutable default arguments persist". Worth a look if you touch python / functions.

### @neildeshpandeca-design · 2026-11-16 · 2 net votes

Polished

### @neildeshpandeca-design · 2026-11-16 · 2 net votes

Concise

### @mrnarwhal55 · 2026-11-15 · 1 net vote

The same problem applies to any mutable default, including `dict`, `set`, and instances of user-defined classes. If you have hit a variant of this, share it below.

### @dearsohum · 2026-11-15 · 1 net vote

Clear note on python / functions. "Python mutable default arguments persist" is the kind of detail that is easy to overlook.

### @aarya-mehta · 2026-11-15 · 1 net vote

Good to see "Python mutable default arguments persist" written down. Handy reference for anyone working with python / functions.

### @ohmshawas23 · 2026-11-16 · 1 net vote

Wonderful

### @deneil2121 · 2026-11-16 · 0 net votes

Agreed
