英文文件:
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#exception
說明:
1. 函數
功能用於判斷一個類型物件是否是另一個類型物件的子類,class參數表示需要檢查的類型對象,calssinfo參數表示需要對比類型對象。 2. 如果class參數是classinfo類型物件(或classinfo類別物件的直接、間接、虛擬子類別)的實例,則傳回True。>>> issubclass(bool,int) True >>> issubclass(bool,(str)) False >>> class A: pass >>> class B(A): pass >>> issubclass(B,A) True
>>> class A: pass >>> issubclass(A,A) True
>>> issubclass(bool,int) True>>> issubclass(bool,str) False>>> issubclass(bool,(str,int)) True
>>> 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
以上是Python內建issubclass函數的詳細介紹的詳細內容。更多資訊請關注PHP中文網其他相關文章!