问题 If I try running python test.py -bf with the below code, I get bar=f and foo=foo1 instead of the desired result ( bar=bar1 and foo=foo1 ). How would I achieve the desired result? import argparse ap = argparse.ArgumentParser(description='test') ap.add_argument('--bar', '-b', nargs='?', const='bar1') ap.add_argument('--foo', '-f', nargs='?', const='foo1') args = ap.parse_args() 来源: https://stackoverflow.com/questions/62747802/argparse-nargs-with-multiple-flags-in-one-dash