For non-negative (unsigned) integers only, use isdigit():

>>> a = "03523"
>>> a.isdigit()
True
>>> b = "963spam"
>>> b.isdigit()
False

Documentation for isdigit(): Python2, Python3

For Python 2 Unicode strings: isnumeric().

Answer from Zoomulator on Stack Overflow
🌐
PythonHow
pythonhow.com › how › check-if-a-string-is-a-float
Here is how to check if a string is a float in Python
To check if a string is a number (float) in python, you can use isnumeric() in combination with the replace() method to check if the string can be casted to float or not.
🌐
Python Forum
python-forum.io › thread-37288.html
Detecting float or int in a string
May 23, 2022 - The str.isnumeric() function is lacking when it comes to detecting floats. Several sites say to use a try/except to attempt the conversion. I was taught not to depend on try except in the regular program flow, and that it should only be used in the c...
🌐
Squash
squash.io › pythons-numeric-capabilities
How to Use Python's isnumeric() Method - Squash Labs
September 27, 2024 - Performing Arithmetic Operations in Python · Comparison of int, float, and complex Data Types · Table of Contents · The isnumeric() method is a built-in method in Python that allows us to check if a string consists of only numeric characters.
🌐
Miguendes
miguendes.me › python-isdigit-isnumeric-isdecimal
How to Choose Between isdigit(), isdecimal() and isnumeric() in Python
September 18, 2021 - In this section, we'll see how to fix the most common problems when using isdigit, isnumeric, and isdecimal. The best way to check that is to try to cast it to float. It the float constructor doesn't raise any exceptions, then the string is a valid float. This is a pythonic idiom called EAFP ...
🌐
EyeHunts
tutorial.eyehunts.com › home › python isnumeric float
Python isnumeric float - Tutorial - By EyeHunts
February 16, 2023 - def isfloat(num): try: float(num) return True except ValueError: return False print(isfloat('s12')) print(isfloat('1.123')) print(isfloat('Hello')) ... Do comment if you have any doubts or suggestions on this Python isnumeric method topic.
🌐
GeeksforGeeks
geeksforgeeks.org › python-check-for-float-string
Python - Check for float string - GeeksforGeeks
January 11, 2025 - This method is especially useful when we want to ensure that user inputs or string data are stri ... The isnumeric() method is a built-in method in Python that belongs to the string class.
Find elsewhere
🌐
Wsldp
elearning.wsldp.com › python3 › python-check-string-is-a-number
Learn How to Check if a String Is a Number in Python 3
August 9, 2021 - To check if a string is a float, we can use a try-except statement. Python str.isnumeric() function will return True if the given string is numeric or return False otherwise.
🌐
datagy
datagy.io › home › python posts › python strings › choose between python isdigit(), isnumeric(), and isdecimal()
Choose Between Python isdigit(), isnumeric(), and isdecimal() • datagy
December 19, 2022 - If the function does not raise a ValueError, then the string represents a float. This isn’t always the most intuitive way of doing this is to develop a function that accomplishes this. The added benefit of this is that we can return a boolean value, which will not break out program. Let’s see how we can develop a Python function to check if a string representing a float is numeric:
🌐
Learn By Example
learnbyexample.org › python-string-isnumeric-method
Python String isnumeric() Method - Learn By Example
April 20, 2020 - Below are a few examples where isnumeric() method returns false. # floating point number S = '123.456' x = S.isnumeric() print(x) # Prints False # number with thousands separator S = '1,234,567' x = S.isnumeric() print(x) # Prints False # empty string S = '' x = S.isnumeric() print(x) # Prints False ·
🌐
Python documentation
docs.python.org › 3 › library › stdtypes.html
Built-in Types — Python 3.14.3 documentation
February 25, 2026 - Also referred to as integer division. For operands of type int, the result has type int. For operands of type float, the result has type float. In general, the result is a whole integer, though the result’s type is not necessarily int.
🌐
Programiz
programiz.com › python-programming › examples › check-string-number
Python Program to Check If a String Is a Number (Float)
To understand this example, you should have the knowledge of the following Python programming topics: ... def isfloat(num): try: float(num) return True except ValueError: return False print(isfloat('s12')) print(isfloat('1.123'))
🌐
NCL
ncl.ucar.edu › Document › Functions › Built-in › isnumeric.shtml
isnumeric
; float x1d = (/1.,2.,3./) ; float str = "This is a string" ; string IS_DONE = False ; logical ;---These are all False print(isbyte(i)) print(isunsigned(i)) print(ischar(str)) print(isnumeric(str)) print(islogical(IS_DONE)) ;---These are all True print(isfloat(xscalar)) print(isfloat(x1d)) print(issigned(i)) print(isstring(str)) print(isnumeric(i))
🌐
Vultr
docs.vultr.com › python › examples › check-if-a-string-is-a-number-float
Python Program to Check If a String Is a Number (Float) | Vultr Docs
December 6, 2024 - This function tries to convert the string s to a float. If successful, it returns True, indicating the string can be interpreted as a float. If it raises a ValueError, it returns False, indicating the string is not a valid float.
🌐
Quora
quora.com › How-do-you-check-if-a-number-is-a-float-in-Python
How to check if a number is a float in Python - Quora
If it is not float you can convent it into float using the function float(). ... How can I check whether or not a user input in Python is a float or an integer without using try error checking?
🌐
Spark By {Examples}
sparkbyexamples.com › home › python › python string isnumeric
Python String isnumeric - Spark By {Examples}
May 21, 2024 - # integer validation number = 50 ... validating a float number (number = 8.49) by converting it to a string and then using the isnumeric() method after removing the decimal point....