python中的isinstance(对象,类型)

vin*_*eel 10 python python-3.x

我只是通过一些python帮助文档,并遇到了以下代码:

isinstance(object, type)
Run Code Online (Sandbox Code Playgroud)

任何人都可以解释上述陈述中的类型意味着什么?

谢谢,Vineel

Fre*_*Foo 13

type必须是表示类型/类的对象,例如intstr.例如,在isinstance(1, int)评估Trueisinstance(sys.stdin, str)评估为False.如果你已经定义了a class Foo,那么Foo它也是一个类型对象.

编辑:正如@delnan所说,type它本身也是Python中的一个类型,所以isinstance(str, type)是真的,因为它str是一个类型,isinstance('foo', type)而是假的.object也是Python中的一个类型,是类型层次结构的根.