擅长:python、mysql、java
<pre><code>def is_float(string):
try:
return float(string) and '.' in string # True if string is a number contains a dot
except ValueError: # String is not a number
return False
</code></pre>
<p>输出:</p>
<pre><code>>> is_float('string')
>> False
>> is_float('2')
>> False
>> is_float('2.0')
>> True
>> is_float('2.5')
>> True
</code></pre>