title: How to make an optional value for argument using argparse?
body: <p>I am creating a python script where I want to have an argument that manipulates how many search results you get as output. I've currently named the argument <code>--head</code>. This is the functionality I'd like it to have:</p>
  
  <ol>
  <li><p>When <code>--head</code> is not passed at the command line I'd like it to default to one value. In this case, a rather big one, like 80</p></li>
  <li><p>When <code>--head</code> is passed without any value, I'd like it to default to another value. In this case, something limited, like 10 </p></li>
  <li><p>When <code>--head</code> is passed with a value, I'd like it to store the value it was passed.</p></li>
  </ol>
  
  <p>Here is some code describing the problem:</p>
  
  <pre><code>&gt;&gt;&gt; import argparse
  &gt;&gt;&gt; parser = argparse.ArgumentParser()
  &gt;&gt;&gt; parser.add_argument('-h',
                          '--head',
                          dest='size',
                          const=80,
                          default=10,
                          action="I don't know",
                          help='Only print the head of the output')
  &gt;&gt;&gt; # OFC, that last line will fail because the action is uknown,
  ... # but here is how I'd like it to work
  ... parser.parse_args(''.split())
  Namespace(size=80)
  &gt;&gt;&gt; parser.parse_args('--head'.split())
  Namespace(size=10)
  &gt;&gt;&gt; parser.parse_args('--head 15'.split())
  Namespace(size=15)
  </code></pre>
  
  <p>I know I probably can write a custom action for this, but I first want to see if there is any default behaviour that does this.</p>