Use isinstance.

>>> x = 12
>>> isinstance(x, int)
True
>>> y = 12.0
>>> isinstance(y, float)
True

So:

>>> if isinstance(x, int):
        print('x is a int!')

x is a int!

In case of long integers, the above won't work. So you need to do:

>>> x = 12L
>>> import numbers
>>> isinstance(x, numbers.Integral)
True
>>> isinstance(x, int)
False
Answer from user225312 on Stack Overflow
Discussions

Why do we need to differentiate between float numbers and integers?
There are many reasons: It is faster for the computer to do math with integers than with floats. Floats accumulate errors, so if you don't need them, integers are more robust. For example 0.1+0.2 != 0.3. There are situations in which floats don't make sense but integers do. For example when accessing an item in a list, my_list[3] makes sense but my_list[3.57] does not. Every programming language (except JavaScript) also separates them. Many also have more than 1 type of int and float (for different sizes). More on reddit.com
๐ŸŒ r/learnpython
9
5
August 13, 2022
Float and int function
float() and int() are mainly use to convert strings to numbers. They actually create a number from the strings. int() is also often use to create an integer number from a float number. A classic example is when you ask the user for a number. The input function always returns a string of character. To perform calculation you need a number (int or float). So you must create a number from that string. As in: string_number = input("Enter temperature in ยฐF (integer): ") temp_far = int(string_number) temp_cel = (temp_far-32) * (5/9) # the result here is a float print("Temperature in celsius (float)", temp_cel) temp_cel_int = int(temp_cel) # creates an integer number from the float print("Temperature in Celsius (integer)", temp_cel_int) Using float on strings from math import radians angle_string = input("Enter a precise angle in degrees with decimal: ") angle_float = float(angle_string) radians_float = radians(angle_float) print("That angle in degrees is",radians_float,"in radians") More on reddit.com
๐ŸŒ r/learnpython
10
5
March 25, 2023
Make float.__(i/r)floordiv__ return an int - Ideas - Discussions on Python.org
The // operation is made to return an integer value. However, when either operand is a float, the result is an integer in the form (type) of a float. I think there are several advantages to making this return an int. For one, there is no circumstance using the standard types where // would ... More on discuss.python.org
๐ŸŒ discuss.python.org
3
March 18, 2023
python - ().is_integer() not working - Stack Overflow
A quick fix would be to change ... and give you a float instance on which you can call the is_integer() method like you are trying to. Do this: ... Sign up to request clarification or add additional context in comments. ... You are using Python 2.7.... More on stackoverflow.com
๐ŸŒ stackoverflow.com
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ check-if-value-is-int-or-float-in-python
Check If Value Is Int or Float in Python - GeeksforGeeks
July 1, 2025 - type() function returns the type of the object you pass to it. Itโ€™s a quick and easy way to inspect whether a value is an int or a float. ... Explanation: type() function returns the data type of the variable.
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ why do we need to differentiate between float numbers and integers?
r/learnpython on Reddit: Why do we need to differentiate between float numbers and integers?
August 13, 2022 -

Hi all. Im a complete beginner learning the basics. Im curious as to why Python has two different types of numbers (3 including complex) : Floats and integers. Why cant we just use any number and if we do wanna use a decimal point, we just use a decimal point without having to indicate it as a float? What is the significance of differentiating the two? Thanks!

Top answer
1 of 7
9
There are many reasons: It is faster for the computer to do math with integers than with floats. Floats accumulate errors, so if you don't need them, integers are more robust. For example 0.1+0.2 != 0.3. There are situations in which floats don't make sense but integers do. For example when accessing an item in a list, my_list[3] makes sense but my_list[3.57] does not. Every programming language (except JavaScript) also separates them. Many also have more than 1 type of int and float (for different sizes).
2 of 7
4
we just use a decimal point without having to indicate it as a float We can? print(type(1.5)) # There are at least 2 very good reasons to have separate types, though. The first is logical. Floating point math is inexact. For example: >>> (1 - 0.1) - 0.9 0.0 >>> (1 - 0.05 - 0.05) - 0.9 -1.1102230246251565e-16 As you can see, the more calculations with make with floating point arithmetic, the more likely it is we'll accumulate inaccuracies. This does not happen with integers, and we would certainly like to have the option of avoiding this problem whenever possible. It's not possible to eliminate this problem in rational numbers without giving a fractional number unlimited storage space, which is obviously undesirable in a variety of use cases. The second is practical. The algorithms for integer arithmetic are dramatically different. Integer arithmetic uses 2's complement, and floating point arithmetic uses the IEEE 754 standard for representing decimal numbers and performing computations on them. These different representations are what allows us to preserve precision in integers. Also, integer arithmetic is much faster than floating point arithmetic. When only integer arithmetic is needed over a large amount of data, computation will be significantly faster.
๐ŸŒ
Note.nkmk.me
note.nkmk.me โ€บ home โ€บ python
Check If a Number Is an Integer in Python | note.nkmk.me
April 23, 2025 - The float type provides an is_integer() method, which returns True if the value is an integer and False otherwise.
๐ŸŒ
CodingNomads
codingnomads.com โ€บ python-float-python-integer
Python Float and Python Integer
You might call both 1 and 2.5 ... are: Integers: Whole numbers without a decimal point, such as 1 ยท Floating-Point Numbers: Decimal numbers, such as 1.23...
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ python_numbers.asp
Python Numbers
... x = 1 y = 35656222554887711 z = -3255522 print(type(x)) print(type(y)) print(type(z)) Try it Yourself ยป ยท Float, or "floating point number" is a number, positive or negative, containing one or more decimals.
Find elsewhere
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ float and int function
r/learnpython on Reddit: Float and int function
March 25, 2023 -

Hello, please can someone explain to me when to use the float and int functions?

I mean should I use float when I am strictly dealing with decimal numbers, or when I want to convert whole numbers to decimal numbers?

pythonlearner

Top answer
1 of 4
5
float() and int() are mainly use to convert strings to numbers. They actually create a number from the strings. int() is also often use to create an integer number from a float number. A classic example is when you ask the user for a number. The input function always returns a string of character. To perform calculation you need a number (int or float). So you must create a number from that string. As in: string_number = input("Enter temperature in ยฐF (integer): ") temp_far = int(string_number) temp_cel = (temp_far-32) * (5/9) # the result here is a float print("Temperature in celsius (float)", temp_cel) temp_cel_int = int(temp_cel) # creates an integer number from the float print("Temperature in Celsius (integer)", temp_cel_int) Using float on strings from math import radians angle_string = input("Enter a precise angle in degrees with decimal: ") angle_float = float(angle_string) radians_float = radians(angle_float) print("That angle in degrees is",radians_float,"in radians")
2 of 4
1
For string conversion, use the one appropriate to the string you're trying to convert. If you care about exact equality, don't use floats. Use integers, or maybe the Decimal class. If you want to know if floats are equal ish, keep in mind that the ish is always there. Use something like math.isclose to make such checks. There is rarely (almost never?) any need to explicitly convert integers to floats (unless you're doing something with numpy or similar). Integers will be automatically treated as floats during division (NOTE: different in some other languages), multiplication, etc. If you want to convert a float to integer, you can do that via int(2.3), but keep in mind how it rounds. There are other rounding functions that may or may not be more helpful (math.ceil, math.floor, round).
๐ŸŒ
Python.org
discuss.python.org โ€บ ideas
Make float.__(i/r)floordiv__ return an int - Ideas - Discussions on Python.org
March 18, 2023 - The // operation is made to return an integer value. However, when either operand is a float, the result is an integer in the form (type) of a float. I think there are several advantages to making this return an int.
๐ŸŒ
Pythonhumanities
pythonhumanities.com โ€บ home โ€บ lesson 04: python integers and floats
Lesson 04: Python Integers and Floats - Python for Digital Humanities
January 4, 2021 - The way in which you create a number ... has a decimal, Python will automatically consider it a float. If it does not, it will automatically consider it an integer....
๐ŸŒ
Snakify
snakify.org โ€บ integer and float numbers
Integer and float numbers - Learn Python 3 - Snakify
When we read an integer value, ... to integer using int(). When we read a floating-point number, we need to cast the string to float using float(): ... Floats with very big or very small absolute value can be written using a scientific notation.
Top answer
1 of 15
590

To check if a float value is a whole number, use the float.is_integer() method:

>>> (1.0).is_integer()
True
>>> (1.555).is_integer()
False

The method was added to the float type in Python 2.6.

Take into account that in Python 2, 1/3 is 0 (floor division for integer operands!), and that floating point arithmetic can be imprecise (a float is an approximation using binary fractions, not a precise real number). But adjusting your loop a little this gives:

>>> for n in range(12000, -1, -1):
...     if (n ** (1.0/3)).is_integer():
...         print n
... 
27
8
1
0

which means that anything over 3 cubed, (including 10648) was missed out due to the aforementioned imprecision:

>>> (4**3) ** (1.0/3)
3.9999999999999996
>>> 10648 ** (1.0/3)
21.999999999999996

You'd have to check for numbers close to the whole number instead, or not use float() to find your number. Like rounding down the cube root of 12000:

>>> int(12000 ** (1.0/3))
22
>>> 22 ** 3
10648

If you are using Python 3.5 or newer, you can use the math.isclose() function to see if a floating point value is within a configurable margin:

>>> from math import isclose
>>> isclose((4**3) ** (1.0/3), 4)
True
>>> isclose(10648 ** (1.0/3), 22)
True

For older versions, the naive implementation of that function (skipping error checking and ignoring infinity and NaN) as mentioned in PEP485:

def isclose(a, b, rel_tol=1e-9, abs_tol=0.0):
    return abs(a - b) <= max(rel_tol * max(abs(a), abs(b)), abs_tol)
2 of 15
73

We can use the modulo (%) operator. This tells us how many remainders we have when we divide x by y - expresses as x % y. Every whole number must divide by 1, so if there is a remainder, it must not be a whole number.

This function will return a boolean, True or False, depending on whether n is a whole number.

def is_whole(n):
    return n % 1 == 0
๐ŸŒ
Quora
quora.com โ€บ What-is-is_integer-in-Python
What is is_integer() in Python? - Quora
In Python, is_integer() is a method for float objects that checks if the number has no decimal part.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ difference-between-integer-and-float-in-python
Difference Between Integer and Float in Python - GeeksforGeeks
July 23, 2025 - Positive Integer: 42 Negative Integer: -17 Large Integer: 9876543210123456789012345678901234567890 Sum Result: 25 Product Result: 414814814825185185138518518513851851851380 ยท In Python, a float is a numeric data type representing decimal numbers.
๐ŸŒ
Learn By Example
learnbyexample.org โ€บ python-float-is_integer-method
Python float.is_integer() Method - Learn By Example
April 19, 2024 - If a float has no fractional part after the decimal point (like 20.0), itโ€™s considered an integer from a representational perspective, and float.is_integer() would return True.
๐ŸŒ
Codedamn
codedamn.com โ€บ news โ€บ python
Converting Float to Int in Python: A Step-by-Step Guide
July 3, 2023 - This function truncates the decimal ... to an int in Python, it's important to note that Python does not round the number to the nearest integer; instead, it truncates it....