Check If Value Is Int or Float in Python Last Updated : 01 Jul, 2025 Comments Improve Suggest changes Like Article Like Report In Python, you might want to see if a number is a whole number (integer) or a decimal (float). Python has built-in functions to make this easy. There are simple ones like type() and more advanced ones like isinstance(). In this article, we'll explore different ways to do this efficiently. Using type() Functiontype() 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. Python a = 14 b = 2.3 print(type(a)) print(type(b)) Output<class 'int'> <class 'float'> Explanation: type() function returns the data type of the variable. Here, a is an integer and b is a float, so the respective types are printed.Using isinstance() Functionisinstance() function checks if an object is an instance of a given data type. It returns True or False. Python a = 654 b = 566.8 print(isinstance(a, int)) print(isinstance(a, float)) print(isinstance(b, int)) print(isinstance(b, float)) OutputTrue False False True Explanation: Here, we check each variable a and b against both int and float. a is correctly identified as an integer and b as a float. Using isdigit() Functionisdigit() method is used to check if all characters in a string are digits. It's commonly used for string inputs. Python a = '345.5' res = a.isdigit() if res == True: print("The number is an integer") else: print("The number is a float") OutputThe number is a float Explanation: Although '345.5' represents a number, the presence of the decimal point (.) causes isdigit() to return False. This is because isdigit() expects only digits (0–9) in the string, without any non-digit characters.Related Articlestype() FunctionDifference Between == and is in PythonConverting Strings to Integers and Floats in PythonHandling User Input and Data Types in Python Comment More infoAdvertise with us Next Article Check If Value Is Int or Float in Python E everythingtech Follow Improve Article Tags : Python Geeks Premier League Geeks Premier League 2023 Practice Tags : python Similar Reads Check if the value is infinity or NaN in Python In this article, we will check whether the given value is NaN or Infinity. This can be done using the math module. Let's see how to check each value in detail. Check for NaN values in Python NaN Stands for "Not a Number" and it is a numeric datatype used as a proxy for values that are either mathema 4 min read Check For NaN Values in Python In data analysis and machine learning, missing or NaN (Not a Number) values can often lead to inaccurate results or errors. Identifying and handling these NaN values is crucial for data preprocessing. Here are five methods to check for NaN values in Python. What are Nan Values In In Python?In Python 2 min read Check for True or False in Python Python has built-in data types True and False. These boolean values are used to represent truth and false in logical operations, conditional statements, and expressions. In this article, we will see how we can check the value of an expression in Python.Common Ways to Check for True or FalsePython pr 2 min read Check If String is Integer in Python In this article, we will explore different possible ways through which we can check if a string is an integer or not. We will explore different methods and see how each method works with a clear understanding.Example:Input2 : "geeksforgeeks"Output2 : geeksforgeeks is not an IntigerExplanation : "gee 4 min read Python - Check for float string Checking for float string refers to determining whether a given string can represent a floating-point number. A float string is a string that, when parsed, represents a valid float value, such as "3.14", "-2.0", or "0.001".For example:"3.14" is a float string."abc" is not a float string.Using try-ex 2 min read Like