title: Default value for optional argument in Python:
body: <p>I have the following method:</p>
  
  <pre><code>def get_data(replace_nan=False):
      if replace_nan is not False
          data[numpy.isnan(data)] = replace_nan
          return data
      else:
          return data[~numpy.isnan(data)]
  </code></pre>
  
  <p>So, if <code>replace_nan</code> is False, we return some data array but remove <code>NaN</code>s, and if it's anything else, we replace <code>NaN</code>s with the argument.</p>
  
  <p>Problem is, I may want to replace <code>NaN</code> with <code>False</code>. Or anything else, for that sake. What's the most pythonic way to do so? This:</p>
  
  <pre><code>def get_data(**kwargs):
      if "replace_nan" in kwargs:
         ...
  </code></pre>
  
  <p>works, but is semantically ugly (because we're really just interested in one keyword argument, <code>replace_nan</code>) Any suggestions how to handle this case?</p>