# check if a number is int or float
isinstance(x, int) # integer
isinstance(x, float) # float
import numbers
isinstance(x, numbers.Integral) # Long Int
>>> def isFloatInteger(float):
>>> return float.is_integer()
>>> isFloatInteger(0.62)
False
>>> isFloatInteger(1.00)
True
>>> x = 12
>>> isinstance(x, int)
True
>>> y = 12.0
>>> isinstance(y, float)
True
Check if object is int or float: isinstance()
Check if float is integer: is_integer()
Check if numeric string is integer:
def is_integer(n):
try:
float(n)
except ValueError:
return False
else:
return float(n).is_integer()
number = 25.9
check_int = isinstance(25.9, int)
print(check_int)
OUTPUT
False
check_float = isinstance(25.9, float)
print(check_float)
OUTPUT
True