Sprawdź, czy Float to Python Integer
>>> def isFloatInteger(float):
>>> return float.is_integer()
>>> isFloatInteger(0.62)
False
>>> isFloatInteger(1.00)
True
pi junky
>>> def isFloatInteger(float):
>>> return float.is_integer()
>>> isFloatInteger(0.62)
False
>>> isFloatInteger(1.00)
True
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"
# 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"