Sololearn: Learn to Code
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3
Sure! If you have class A and class B, you can define class C(A,B). Try this code: class A: varA = 5 def __init__(self,v): self.v = v def methodA(self): print(self.v) class B: varB = 9 def __init__(self,g): self.g = g def methodB(self): print(self.g) class C(A,B): varC = 13 def __init__(self,v,g,h): self.v = v self.g = g self.h = h def methodC(self): print(self.h) instC = C(15,17,19) print(instC.v) print(instC.g) print(instC.h) instC.methodA() instC.methodB() instC.methodC() print(instC.varA) print(instC.varB) print(instC.varC)
11th Oct 2016, 4:32 PM
novice