python 判断一个字符串是否是小数

"""
练习判断一个小数
1、判断是否合法
2、合法需要有一个小数点
3、小数点左边必须是个整数,右边必须是个正整数

"""

def xiaoshu(s):
xiaoshu_new=str(s)

if xiaoshu_new.count(".") ==1:
left,right = xiaoshu_new.split(".")
if left.isdigit() and right.isdigit():
print(1111)
return True

elif left.startswith('-') and left.count('-') == 1 and right.isdigit():
lleft = left.split('-')[-1]
if lleft.isdigit():
return True

return False


a = xiaoshu(-.1)

print(a)

猜你喜欢

转载自www.cnblogs.com/wangyajuanjuan/p/11588594.html