day5_函数_判断小数

def check_float(s):
    '''
    #这个函数的作用就是判断传入的字符串是否是合法的消失
    :param s: 传入一个字符串
    :return: True/False
    '''
    s = str(s)
    if s.count('.') == 1:
        s_split = s.split('.')
        left,right = s_split  #正好有两个元素
        # left = s_split[0]
        # right = s_split[1]
        if left.isdigit() and right.isdigit():
            return True
        elif left.startswith('-') and left[1:].isdigit() and right.isdigit():
            return True
    return False
#正小数
#1、小数点个数为1
#2、小数点左边和右边都是整数
#负小数
#1、小数点个数为1
#2、小数点左边和右边都是整数
#3、负号开头,并且只有一个负号
原文地址:https://www.cnblogs.com/once-again/p/9623350.html