English documents:
Isinstance (object, ClassInfo)
Return true if the object argument is an instance of the ClassInfo argument, or of a (direct, indirect or virtual) Subclas s thereof. If object is a object of the given type, the function always returns FALSE. If ClassInfo is a tuple of type objects (or recursively, and other such tuples), return True if object was an instance of any O f the types. If ClassInfo is a type or a tuple of types and such tuples, a TypeError exception is raised.
Description
1. The function function is used to determine whether an object is an instance of a type object, which represents the object to be inspected, and the Calssinfo parameter represents the type object.
2. Returns true if the object parameter is an instance of the ClassInfo type (or the direct, indirect, virtual subclass of the ClassInfo class object).
>>> isinstance (1,int) true>>> isinstance (1,STR) false# define 3 categories: C Inherit b,b inherit A>>> class A: Pass>>> class B (A): pass>>> class C (b): pass>>> a = a () >>> B = B () >>& Gt c = C () >>> isinstance (a,a) #直接实例True >>> isinstance (A, B) false>>> isinstance (b,a) #子类实例 True >>> isinstance (c,a) #孙子类实例True
3. Always return FALSE if the object parameter is passed in to a type.
>>> Isinstance (STR,STR) False >>> Isinstance (Bool,int) False
4. If the ClassInfo type object is a tuple of multiple type objects, returns True if the Object object is an instance of any type object in the tuple, otherwise false is returned.
>>> Isinstance (A, (b,c)) false>>> isinstance (A, (a,b,c)) True
5. If the ClassInfo type object is not a type object or a tuple of multiple type objects, an error (TYPEERROR) will be made.
>>> isinstance (A,[a,b,c]) Traceback (most recent call last): File " <pyshell#23> ", line 1, in <module> isinstance (A,[a,b,c]) typeerror:isinstance () Arg 2 must be a type or tup Le of types