For exponential notation and discrimination up to nan
import re
def isd(N):
return bool(re.compile("^[-+]?([0-9]+(\.[0-9]*)?|\.[0-9]+)([eE][-+]?[0-9]+)?$|nan$|^[-+]?inf$").match(N))
for i in ['-3.', '0.', '5..', '0.1', '1', '1e+2', 'b0', '0c', 'test','nan','1ee-3','1.3e-3','1.3e-3.','00.','5.0.','inf']:
print('{0:9} {1}'.format(i,isd(i)))
Output result
-3. True
0. True
5.. False
0.1 True
1 True
1e+2 True
b0 False
0c False
test False
nan True
1ee-3 False
1.3e-3 True
1.3e-3. False
00. True
5.0. False
inf True
Recommended Posts