Python判断是否为小数

def is_float(s):
s = str(s)
if s.count('.') == 1:
left,right = s.split('.') #[1,1]#-s.2
if left.isdigit() and right.isdigit():
return True
elif left.startswith('-') and left.count('-')==1 \
and left[1:].isdigit() and right.isdigit():
return True

return False
posted @ 2021-05-12 08:42  黑。白。  阅读(250)  评论(0)    收藏  举报