title: Use parser.parse_args() with nargs and args rather than command line input
body: <p>I have an <code>argparse</code> argument <code>example</code> that accepts a variable number of strings:</p>
  
  <pre><code>parser.add_argument('--example', nargs='*', required=False, default='')
  </code></pre>
  
  <p>This works fine when using the CLI as usual with command-line input: <code>script.py --example ab cd</code>.</p>
  
  <p>I also want this to work with arguments that are passed to <code>parser.parse_args(args)</code> <a href="https://docs.python.org/3/library/argparse.html#args" rel="nofollow noreferrer">through the <code>args</code> argument</a> from within the program code.</p>
  
  <p>But when I try to pass <code>parser.parse_args(["--example", "ab cd"])</code>, it's interpreted as single string <code>"ab cd"</code> and not as a list of <code>ab</code> and <code>cd</code>.</p>
  
  <p>Similarly, passing <code>parser.parse_args(["--example", "ab", "cd"])</code> is somehow interpreted as single argument, which is a list. So, when accessing <code>args.example[0]</code> I get the list and <code>args.example[1]</code> gets me an error.</p>