相关疑难解决方法(0)

如何检查字符串是否为数字(浮点数)?

检查字符串是否可以在Python中表示为数字的最佳方法是什么?

我目前拥有的功能是:

def is_number(s):
    try:
        float(s)
        return True
    except ValueError:
        return False
Run Code Online (Sandbox Code Playgroud)

这不仅是丑陋而且缓慢,似乎很笨重.但是我没有找到更好的方法,因为调用floatmain函数更糟糕.

python floating-point casting type-conversion

1519
推荐指数
21
解决办法
127万
查看次数

标签 统计

casting ×1

floating-point ×1

python ×1

type-conversion ×1