<br><br><div><span class="gmail_quote">On 20/12/05, <b class="gmail_sendername">Suresh Jeevanandam</b> <<a href="mailto:jm.suresh@gmail.com">jm.suresh@gmail.com</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi,<br>        I have a string like,<br>        s1 = '12e3'<br>        s2 = 'junk'<br><br>        Now before converting these values to float, I want to check if they<br>are valid numbers.<br><br>        s1.isdigit returns False.
<br><br>        Is there any other function which would return True for s1 and False<br>for s2.</blockquote><div><br>
float()  itself can do the checking for you.  <br>
 </div>>>> for n in ['12e3','junk']:<br>
...     try:<br>
...         float(n)<br>
...     except:<br>
...         print "not valid: ",  n<br>
...         <br>
12000.0<br>
not valid: junk<br>
>>> <br>
</div>