需求分析:
1.小数点个数可以使用.count()方法
2.按照小数点进行分割 例如: 1.98 [1,98]
3.正小数:小数点左边是整数,右边也是整数 可以使用.isdigits()方法
4.负小数:小数点左边是是负号开头,但是只有一个负号,右边也是整数
代码如下:
1 def is_fioat(s):
2 s=str(s)
3 if s.count(".")==1:#小数点个数
4 s_list=s.split(".")
5 left = s_list[0]#小数点左边
6 right =s_list[1]#小数点右边
7 if left.isdigit() and right.isdigit():
8 return True
9 elif left.startswith('-') and left.count('_')==1 and left.split('-')[1].isdigit()and right.isdigit():
10 return True
11 return False
相关文章:
-
2022-12-23
-
2022-12-23
-
2022-12-23
-
2022-12-23
-
2022-12-23
-
2021-10-02
-
2021-12-31
-
2021-05-31