python: isdigit int float 使用
>>> num1 = '2.0' >>> print num1.isdigit() False >>> num2 = '2' >>> print num2.isdigit() True >>> num3 = '-3' >>> print num3.isdigit() False >>> num4 = '3.0' >>> print int(num4) Traceback (most recent call last): File "<stdin>", line 1, in <module> ValueError: invalid literal for int() with base 10: '3.0' >>> num5 = '3' >>> print int(num5) 3 >>> num6 = '3' >>> print float(num6) 3.0 >>> num6 = '-3' >>> print int(num6) -3 >>>