title: How do I make a command line argument act as either a flag or a parsed value?
body: <p>How do I specify that a parsed argument should be:</p>
  <ul>
  <li><code>False</code> if not specified</li>
  <li><code>True</code> if present (with no value)</li>
  <li>or the specified value</li>
  </ul>
  <p>For example I would like the following to happen:</p>
  <pre class="lang-py prettyprint-override"><code>import argparse
  
  parser = argparse.ArgumentParser()
  parser.add_argument(&quot;--the_arg&quot;, ...)
  
  print(parser.parse_args([&quot;--the_arg&quot;]).the_arg)              # should print True
  print(parser.parse_args([]).the_arg)                         # should print False
  print(parser.parse_args([&quot;--the_arg&quot;, &quot;my_value&quot;]).the_arg)  # should print &quot;my_value&quot;
  </code></pre>