Demand analysis:
1. Number of decimal points. count()
2. Divide according to the decimal point 1.98 [1,98]
3. Positive decimal: the left side of the decimal point is an integer, and the right side is also an integer. isdigits() Negative decimal: the left side of the decimal point is a negative sign At the beginning, but there is only one negative sign, and the right side is also an integer. The
code is as follows:
1 def is_fioat(s): 2 s= str(s) 3 if s.count( " . " )==1: #Number of decimal points 4 s_list=s. split( " . " ) 5 left = s_list[0] # 6 to the left of the decimal point right =s_list[1] # 7 to the right of the decimal point 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