def isfloat(num):
try:
float(num)
return True
except ValueError:
return False
print(isfloat('s12'))
print(isfloat('1.123'))
# check if a number is int or float
isinstance(x, int) # integer
isinstance(x, float) # float
import numbers
isinstance(x, numbers.Integral) # Long Int
try:
float(element)
except ValueError:
print "Not a float"
# Interger will be flaged as True as well.
def isfloat(num):
try:
float(num)
return True
except ValueError:
return False
print(isfloat('s12'))
False
print(isfloat('1.123'))
True
print(isfloat('456'))
True
import re
if re.match(r'^-?d+(?:.d+)$', element) is None:
print "Not float"