如果Python字符串变量中已经存储了整数、浮点数或非数字字符串,有没有一种简单的方法来测试该值的“类型”?
下面的代码是真实的(当然正确的):
更多无意义的话:
下面的代码是真实的(当然正确的):
>>> strVar = "145"
>>> print type(strVar)
<type 'str'>
>>>
但是是否有Python函数或其他方法可以让我从上面设置的strVar中返回'int'呢?
也许像下面这段无意义的代码和结果一样...
>>> print typeofvalue(strVar)
<type 'int'>
更多无意义的话:
>>> print type(unquote(strVar))
<type 'int'>
var = "Hello 20"
中是否“包含一个数字”? - NullUserException