How to check if a string can be converted to float in Python

1 Answer

0 votes
def isfloat(s):
    try:
        float(s)
        return True
    except ValueError:
        return False

s = "3.14"

if isfloat(s):
    print("true")
else:
    print("false")


'''
run:

true

'''

 



answered Aug 30, 2018 by avibootz
...