is_integer() checks whether a numeric value has no fractional part. It is most commonly used as float.is_integer(), where it returns True for values such as 10.0 and False for values such as 10.5.
This method is useful when input has already been converted to a float but your logic needs whole-number values. The official float.is_integer documentation defines the method, the int.is_integer documentation covers integer compatibility in current Python, and isinstance is the safer tool for type checks.
Related PythonPool guides cover checking if a string is an integer, int to float conversion, integer division, Python data types, and AttributeError.
Basic float.is_integer Example
Call is_integer() on a float to check whether its fractional part is zero.
value = 12.0
print(value.is_integer())
The result is True. The value is stored as a float, but mathematically it represents a whole number.
This is different from asking whether the object is an int. A float can represent a whole-number amount without being the integer type.
Compare Whole And Fractional Floats
The method returns False when a float has any fractional part.
numbers = [4.0, 4.25, -3.0, 0.5]
for number in numbers:
print(number, number.is_integer())
This helps when validating calculations that may produce either whole-number or fractional results.
Negative whole-number floats return True too, because the sign does not create a fractional part.
Parse Text Before Checking
If the input is text, convert it first. Strings do not have the float method.
text_values = ["10", "10.0", "10.5"]
for text in text_values:
number = float(text)
print(text, number.is_integer())
This treats "10" and "10.0" as whole-number values after conversion.
Use a try block around float(text) when user input may contain invalid numeric text.
Write A Safe Helper
When values can be either integers or floats, combine type checks with is_integer().
def is_whole_number(value):
if isinstance(value, int):
return True
if isinstance(value, float):
return value.is_integer()
return False
print(is_whole_number(7))
print(is_whole_number(7.0))
print(is_whole_number(7.2))
This avoids calling is_integer() on unsupported objects. It also makes the difference between type checks and whole-number checks explicit.
Use this helper shape when data can come from APIs, forms, or calculations with mixed numeric types.
Filter Whole-Number Floats
You can use the method inside list comprehensions or filters to keep only whole-number float values.
values = [1.0, 2.5, 3.0, 4.75, 5.0]
whole_values = [value for value in values if value.is_integer()]
print(whole_values)
The result contains only floats whose fractional part is zero.
This is useful when cleaning numeric data before converting whole-number floats to integers.
Handle Special Float Values
Special floating-point values such as infinity and NaN do not represent ordinary whole numbers.
values = [float("inf"), float("-inf"), float("nan"), 8.0]
for value in values:
print(value, value.is_integer())
The finite whole-number float returns True, while special values return False.
If your data may contain NaN or infinity, check for those cases before converting results to integers.
is_integer Versus isinstance
Use is_integer() to ask whether a numeric value has no fractional part. Use isinstance(value, int) to ask whether an object is actually an integer.
Those questions are related but not identical. 7 is an integer object. 7.0 is a float object that represents a whole number. Depending on your validation rule, either one or both may be acceptable.
For indexing, slicing, counts, and repeat operations, Python usually needs an actual integer. For reports or numeric cleanup, a whole-number float may be acceptable after conversion.
Common Mistakes
When a whole-number float should become an integer, convert it only after the check passes. That keeps fractional input from being silently truncated by int(). For example, int(7.9) returns 7, which may hide a validation problem.
For user input, keep the validation steps separate: parse the text, check whether the numeric value is whole, then convert if the program truly needs an integer object. Separate steps make error messages clearer and prevent accidental data loss.
For financial, scientific, or high-precision data, consider whether binary floating-point is the right representation. A value can look simple in decimal text but become slightly different as a float. In those cases, use a decimal or domain-specific numeric type before applying whole-number rules.
Do not call is_integer() on a string. Convert the string first, or use a string-specific integer check.
Do not assume a True result means the object is an int. It only means the numeric value has no fractional part.
Do not convert very large floats to integers without checking whether precision matters. Floating-point representation can lose exactness for very large numbers.
The practical rule is to use float.is_integer() for whole-number checks on floats, and use isinstance() when type identity is what your code actually needs.