检查字符串是否可以在Python中表示为数字的最佳方法是什么?
我目前拥有的功能是:
def is_number(s): try: float(s) return True except ValueError: return False
这不仅是丑陋而且缓慢,似乎很笨重.但是我没有找到更好的方法,因为调用floatmain函数更糟糕.
float
python floating-point casting type-conversion
casting ×1
floating-point ×1
python ×1
type-conversion ×1