title: How do I check if a string represents a number (float or int)?
body: <p>How do I check if a string represents a numeric value in Python?</p>
  <pre><code>def is_number(s):
      try:
          float(s)
          return True
      except ValueError:
          return False
  </code></pre>
  <p>The above works, but it seems clunky.</p>
  <hr />
  <p><sub>If what you are testing comes from user input, it is <em>still</em> a string <em>even if it represents</em> an <code>int</code> or a <code>float</code>. See <a href="https://stackoverflow.com/questions/20449427/">How can I read inputs as numbers?</a> for converting the input, and <a href="https://stackoverflow.com/questions/23294658/">Asking the user for input until they give a valid response</a> for ensuring that the input represents an <code>int</code> or <code>float</code> (or other requirements) before proceeding.</sub></p>