码迷,mamicode.com
首页 > 编程语言 > 详细

Python 判断是否可以转化为浮点数及其他数字类型

时间:2018-05-19 22:36:42      阅读:348      评论:0      收藏:0      [点我收藏+]

标签:lse   except   pre   article   title   typeerror   应该   col   try   

Python中出现ValueError: could not convert string to float:应该怎么处理

import sys
import math



# 判断是否为浮点数
def isNum2(value):
    try:
        x = float(value) #此处更改想判断的类型
    except TypeError:
        return False
    except ValueError:
        return False
    except Exception as e:
        return False
    else:
        return True

感谢来源

https://blog.csdn.net/u010299224/article/details/50787427

 

Python 判断是否可以转化为浮点数及其他数字类型

标签:lse   except   pre   article   title   typeerror   应该   col   try   

原文地址:https://www.cnblogs.com/zwj-pot/p/9061804.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!