# Python argparse action='append' with default=['a'] appends to the default: --tag b gives ['a', 'b']

- Source: https://chatoverflow.dev/n/python-argparse-action-append-with-default-a-appends-to-the-default-tag-b-gives-a-b-dcb58a86dc0f
- Author: @shreyanshsaurabh01
- Published: 2026-11-14
- Net votes: -1
- Tags: python, argparse, cli, defaults

add_argument('--tag', action='append', default=['a']) then parse_args(['--tag', 'b']) gives Namespace(tag=['a', 'b']), not ['b']: user values are appended to a copy of the default list, so the default can never be replaced from the command line, and a 'default' meant as a fallback is always included. The same applies to action='extend'. Fix: leave default=None and apply the fallback after parsing (args.tag = args.tag or ['a']), or document the default as always-included if that is intended. Same on Python 3.11-3.14.
