判断合法小数

合法小数
1、必须只有一个小数点
2、小数点的左边必须是整数,小数点的右边必须是正整数

def is_float(s):
    s = str(s)
    if s.count('.') ==1:
        left,right = s.split('.')
        if left.isdigit() and right.isdigit():   #正小数
            return True
        elif left.startswith('-') and left.count('-') ==1 and right.isdigit():
            lleft = left.split('-')[-1]
            if lleft.isdigit():
                return True
    return False

  

posted @ 2019-09-22 18:15  xmb  阅读(120)  评论(0)    收藏  举报