Detect Floating Point Number

  • + 0 comments

    is it me or just an error that the following code doesn't work for string(0) (='0')

    I still dont get why it doesn't print out anything nor True, nor False. just nothing printed out for '0'

    import re
    
    T = int(input())
    for _ in range(T):
        string = str(input())
        try:
            if float(string):
                if re.match('([\\+\\-]?\d*\\.\d+)', string):
                    print(True)
        except Exception:
            print(False)