Join our newsletter for the latest updates.

Python Program to Check If a String Is a Number (Float)

In this example, you will learn to check if a string is a number (float).

To understand this example, you should have the knowledge of the following Python programming topics:


Using float()

def isfloat(num):
    try:
        float(num)
        return True
    except ValueError:
        return False

print(isfloat('s12'))
print(isfloat('1.123'))

Output

False
True

Here, we have used try except in order to handle the ValueError if the string is not a float.