-
| Isinstance( |
Object, classinfo) |
-
Return true if ObjectArgument is an instance of ClassinfoArgument, or of a (direct or indirect) subclass thereof. Also return true if
ClassinfoIs a type object and ObjectIs an object of that type. If
ObjectIs not a class instance or an object of the given type, the function always returns false. If
ClassinfoIs neither a class object nor a type object, it may be a tuple of class or type objects, or may recursively contain other such tuples (Other sequence types are not accepted). If
ClassinfoIs not a class, type, or tuple of classes, types, and such tuples,
TypeerrorException is raised.
Changed in version 2.2: support for a tuple of type information was added.
Python can get an object type by using the type function:
>>> Lst = [1, 2, 3]
>>> Type (LST)
<Type 'LIST'>
In addition, you can use the isinstance function to determine whether an object is of a known type.
Isinstance description:
Isinstance (object, class-or-type-or-tuple)-> bool
Return whether an object is an instance of a class or of a subclass thereof.
With a type as second argument, return whether that is the object's type.
The form using a tuple, isinstance (x, (a, B,...), is a temporary cut
Isinstance (X, A) or isinstance (X, B) or... (etc .).
The first parameter is the object, and the second is a list of type names or type names. The return value is boolean. Returns true if the object type is the same as that of parameter 2. If the two parameters are a single tuples, true is returned if the object type is the same as one of the type names in the tuples.
>>> Isinstance (LST, list)
True
>>> Isinstance (LST, (INT, STR, list ))
True
>>> Isinstance (LST, (INT, STR, list ))
True