English documentation:
issubclass
(class, classinfo)
Return true if class is a subclass (direct, indirect or virtual) of classinfo. A class is considered a subclass of itself. classinfo may be a tuple of class objects, in which case every entry in classinfo will be checked. In any other case, a TypeError
exception is raised.
Description:
1. FunctionThe function is used to determine whether one type object is a subclass of another type object, class The parameter indicates the type object that needs to be checked, and the calssinfo parameter indicates the type object that needs to be compared.
2. If the class parameter is an instance of a classinfo type object (or a direct, indirect, or virtual subclass of a classinfo class object), return True.
>>> issubclass(bool,int) True >>> issubclass(bool,(str)) False >>> class A: pass >>> class B(A): pass >>> issubclass(B,A) True
3. Any class is a subclass of its own class, that is, when class and calssinfo are passed in the same type, True is returned.
>>> class A: pass >>> issubclass(A,A) True
4. If the classinfo type object is a tuple composed of multiple type objects, and if the class type object is a subclass of any type object of the tuple, True is returned, otherwise False is returned.
>>> issubclass(bool,int) True>>> issubclass(bool,str) False>>> issubclass(bool,(str,int)) True
5. If the classinfo type object is not a type object or a tuple composed of multiple type objects, an error (TypeError) will be reported.
>>> issubclass(bool,[str,int]) Traceback (most recent call last): File "<pyshell#14>", line 1, in <module> issubclass(bool,[str,int]) TypeError: issubclass() arg 2 must be a class or tuple of classes
The above is the detailed content of Detailed introduction to Python's built-in issubclass function. For more information, please follow other related articles on the PHP Chinese website!