title: In python, when argument data type are NaN, how to return an NaN, not an TypeError
body: <p>e.g. I defined an function which needs several input arguments, if some keyword arguments not being assigned, typically there be an TypeError message, but I want to change it, to output an NaN as the result, could it be done?</p>
  
  <pre><code>def myfunc( S0, K ,r....):
      if  S0 = NaN or .....:
  </code></pre>
  
  <p>How to do it?
  Much appreciated.</p>
  
  <p>Edited:</p>
  
  <pre><code>def myfunc(a):
      return a / 2.5 + 5
  
  print myfunc('whatever')
  
  &gt;python -u "bisectnewton.py"
  Traceback (most recent call last):
    File "bisectnewton.py", line 6, in &lt;module&gt;
      print myfunc('whatever')
    File "bisectnewton.py", line 4, in myfunc
      return a / 2.5 + 5
  TypeError: unsupported operand type(s) for /: 'str' and 'float'
  &gt;Exit code: 1
  </code></pre>
  
  <p>What I want is, the myfunc(a) only accpets an number as the input, if some other data type  like a string = 'whatever' inputed, I don't want to just output an default error message, I want it to output something like return 'NaN' to tell others that the input should be an number.</p>
  
  <p>Now I changed it to this, but still not working, 
  btw, is none the same as NaN? I think they're different.</p>
  
  <pre><code>def myfunc(S0):
      if math.isnan(S0):
          return 'NaN'
      return a / 2.5 + 5
  
  print myfunc('whatever')
  
  &gt;python -u "bisectnewton.py"
  Traceback (most recent call last):
    File "bisectnewton.py", line 8, in &lt;module&gt;
      print myfunc('whatever')
    File "bisectnewton.py", line 4, in myfunc
      if math.isnan(S0):
  TypeError: a float is required
  &gt;Exit code: 1
  </code></pre>
  
  <p>Thanks!</p>