小编典典

如何在Python中比较对象的类型?

python

基本上我想这样做:

obj = 'str'
type ( obj ) == string

我试过了:

type ( obj ) == type ( string )

而且没有用。

另外,其他类型呢?例如,我无法复制NoneType


阅读 138

收藏
2020-12-20

共1个答案

小编典典

isinstance()

就您而言,isinstance("this is a string", str)将返回True

您可能还需要阅读以下内容:http :
//www.canonical.org/~kragen/isinstance/

2020-12-20