其他分享
首页 > 其他分享> >

作者:互联网

一. isinstance(obj,cls)

class Foo1:
    def __init__(self):
        self.name = "派大星"

class Foo2:
    def __init__(self):
        self.name = "海绵宝宝"

f1 = Foo1()
f2 = Foo2()

print(isinstance(f1,Foo1))  # True
print(isinstance(f2,Foo1))  # False

二. issubclass(sub,super)

class Foo1:
    def __init__(self):
        self.name = "章鱼哥"

class Bar1(Foo1):
    def run(self):
        print("快跑")

class Bar2:
    def run(self):
        print("快跑")

print(issubclass(Bar1,Foo1))  # True
print(issubclass(Bar2,Foo1))  # False

标签:__,self,class,issubclass,print,isinstance,方法,Foo1,def
来源: https://www.cnblogs.com/songhaixing/p/14196935.html