Python check instances of classes
问题 Is there any way to check if object is an instance of a class? Not an instance of a concrete class, but an instance of any class. I can check that an object is not a class, not a module, not a traceback etc., but I am interested in a simple solution. 回答1: isinstance() is your friend here. It returns a boolean and can be used in the following ways to check types. if isinstance(obj, (int, long, float, complex)): print obj, "is a built-in number type" if isinstance(obj, MyClass): print obj, "is