Passing an optional argument in a function - python
<p>I would like to create a function which can take either 1 or 2 arguments.
Currently, I have a function which takes exactly 2 arguments through CMD:</p>

<pre><code>def test(self,countName,optionalArg):
        if countName == "lowest":
           #something
        if optionalArg == "furthest:
           #something
        else:
           #something else

if __name__ == '__main__':
        countName = sys.argv[1]
        optionalArg = sys.argv[2]

        temp = len(sys.argv)
        for i in xrange(1,temp):

            sys.argv.pop()
</code></pre>

<p>I would then run:</p>

<blockquote>
  <p>python filename.py lowest furthest</p>
</blockquote>

<p>Using this means that passing the second arg is a must. If I try to run my script just by passing one arg, it encounters an error (as expected). My question is, how do you create an optional argument, which could either be passed or not, depending on the situation?</p>

<p>For example:</p>

<blockquote>
  <p>python filename.py lowest</p>
</blockquote>

<p>In this situation, I expect the program to perform the "#something else" script, as nothing was passed and it is different than "furthest".</p>

<p><strong>Please do not write the code for me, I am here to learn :)</strong></p>