热线电话:13121318867

登录
2019-03-26 阅读量: 460
Python支持多重继承吗?

与Java和C ++一样,Python支持多重继承。我们在括号中将所有父类指定为逗号分隔列表。

# Python example to show working of multiple

# inheritance

class Base1(object):

def __init__(self):

self.str1 = "Geek1"

print "Base1"

class Base2(object):

def __init__(self):

self.str2 = "Geek2"

print "Base2"

class Derived(Base1, Base2):

def __init__(self):

# Calling constructors of Base1

# and Base2 classes

Base1.__init__(self)

Base2.__init__(self)

print "Derived"

def printStrs(self):

print(self.str1, self.str2)

ob = Derived()

ob.printStrs()

输出 :

Base1
Base2
Derived
Geek1 True E101
0.0000
1
关注作者
收藏
评论(0)

发表评论

暂无数据
推荐帖子