Set the action argument to append
:
'append' - This stores a list, and appends each argument value to the list. This is useful to allow an option to be specified multiple times.
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("--opt", action='append')
args = parser.parse_args()
print(args.opt)
Demo:
$ python test_argparse.py --opt value1 --opt value2 --opt value3
['value1', 'value2', 'value3']