Real Python

Get Your Code: Click here to download a shopping-list example that reproduces the mutable default argument bug so you can see why it happens.

Almost there! Complete this form and click the button below to gain instant access:

Using Python Optional Arguments When Defining Functions

See the Mutable Default Argument Bug in Action

๐Ÿ”’ No spam. We take your privacy seriously.

ยฉ 2012โ€“2026 Real Python โ‹… Privacy Policy