本文摘自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打印星号金字塔的方法
小白学Python买什么书?
Python如何垂直输出
Python semaphore(信号量)是什么?(实例详解)
Python32位和64位有什么区别
Python中logging的详细介绍(附示例)
Python默认安装路径在哪
Python中tornado下websocket客户端编程的介绍
Python元组怎么排序
Python爬虫能做什么
更多相关阅读请进入《Python》频道 >>
人民邮电出版社
python入门书籍,非常畅销,超高好评,python官方公认好书。
转载请注明出处:木庄网络博客 » 介绍python判断一个数是不是正小数和整数的方法