def isfloat(num):
try:
float(num)
return True
except ValueError:
return False
print(isfloat('s12'))
print(isfloat('1.123'))
def is_number(x):
'''
Takes a word and checks if Number (Integer or Float).
'''
try:
# only integers and float converts safely
num = float(x)
return True
except ValueError as e: # not convertable to float
return False
try:
float(element)
except ValueError:
print "Not a float"
import re
if re.match(r'^-?d+(?:.d+)$', element) is None:
print "Not float"