I need to check if a value is an integer in Python. Note that by integer I mean values like 2, 1.0 and -4.0000, whereas 0.4 a
2
1.0
-4.0000
0.4
float instances have an is_integer method, which tells you whether f == int(f). The following snippet will therefore work for both integers and floats, as well as any strings representing either of those numerical types:
float
is_integer
f == int(f)
float(value).is_integer()