本文摘自php中文网,作者巴扎黑,侵删。
这篇文章主要介绍了python 判断是否为正小数和正整数的实例的相关资料,这里提供实例,实例注释说明很清楚,需要的朋友可以参考下python 判断是否为正小数和正整数的实例
实现代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | def check_float(string):
s = str (string)
if s.count( '.' ) = = 1 :
sl = s.split( '.' )
left = sl[ 0 ]
right = sl[ 1 ]
if left.startswith( '-' ) and left.count( '-' ) = = 1 and right.isdigit():
lleft = left.split( '-' )[ 1 ]
if lleft.isdigit():
return False
elif left.isdigit() and right.isdigit():
return True
elif s.isdigit():
s = int (s)
if s ! = 0 :
return True
return False
|
以上就是介绍python判断一个数是不是正小数和整数的方法的详细内容,更多文章请关注木庄网络博客!!
相关阅读 >>
Python字典之中len方法是什么?len方法有什么作用?
Python如何读取excel文件夹
Python怎么自学要那本书
Python画圆运用了什么函数
Python 装饰器
Python怎么安装pygame
Python写入已存在的excel数据实例
Python中pow是什么
Python判断循环体结束的方法
Python怎么输出汉字
更多相关阅读请进入《Python》频道 >>
人民邮电出版社
python入门书籍,非常畅销,超高好评,python官方公认好书。
转载请注明出处:木庄网络博客 » 介绍python判断一个数是不是正小数和整数的方法