Skip to content

Python是否支持多继承,请举例说明 #112

@Sogrey

Description

@Sogrey

Python支持多继承

class Calculator:
    def calculate(self,expression):
        self.value = eval(expression)
        return self.value

class MyPrint:
    def print(self,msg):
        print('msg:',msg)

class MyCalculator1(Calculator,MyPrint):
    pass

my1 = MyCalculator1()
print(my1.calculate("1+3 * 5"))  ##16 调用了Calculator的calculate方法
my1.print("hello")  ## msg: hello 调用了MyPrint的print方法

Python类可以拥有多个父类

如果Python类的多个父类存在相同的成员,按着什么规则处理 #113

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions