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

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

猜你喜欢

转载自www.cnblogs.com/zwj-pot/p/9061804.html