|
Isinstance( |
Object, classinfo) |
Return true if
Object argument is an instance of
Classinfo argument, or of a (direct or indirect) subclass thereof. Also return true if
Classinfo is a type object and
Object is an object of that type. If
Object is not a class instance or an object of the given type, the function always returns false. If
Classinfo is 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 classinfo is not a class, type, or tuple of classes, types, and such tuples,
Typeerror exception is raised.
Changed in version 2.2: support for a tuple of type information was added.
Isinstance description::
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.
Instance:
Python can get an object type by using the type function:
>>> Lst = [1, 2, 3]
>>> Type (LST)
<Type 'LIST'>
The isinstance function is used to determine whether an object is of a known type.
>>> Isinstance (LST, list)
Trueisinstance (LST, (INT, STR, list ))
True
>>> Isinstance ('ioo', (STR ))
True
>>> Isinstance (32434, (INT ))
True
>>> Isinstance ('safasdf ', (INT, long ))
False
Use CMP to compare the integer size
>>> CMP (3, 2)
1
>>> CMP (20, 30)
-1