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

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM