当前位置:首页 > Python教程 > python技巧

Python判断是否是数字(无法判断浮点数)(已解决)

s为字符串
s.isalnum() 所有字符都是数字或者字母
s.isalpha() 所有字符都是字母
s.isdigit() 所有字符都是数字
s.islower() 所有字符都是小写
s.isupper() 所有字符都是大写
s.istitle() 所有单词都是首字母大写,像标题
s.isspace() 所有字符都是空白字符、t、n、r

             1
            def
             isNum2(value):

             2
            try
            :

             3         x = int(value)
 4except TypeError:
 5return False
 6except ValueError:
 7return False
 8except Exception, e:
 9return False
10else:
11return True
        
            浮点数判断
        
    
type(eval("123")) == int
type(eval("123.23")) == float

 

        

原文:http://www.cnblogs.com/hitnoah/p/3918109.html


【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!

相关教程推荐

其他课程推荐