Answered step by step
Verified Expert Solution
Question
1 Approved Answer
language python # # 18.7.2 illustrating multiple inheritance and the resolution of inheritance conflicts *** *** class MyMainclass: def set_instance_value_1(self, v): self.instance_value_1 = 'set from
language python
# # 18.7.2 illustrating multiple inheritance and the resolution of inheritance conflicts *** *** class MyMainclass: def set_instance_value_1(self, v): self.instance_value_1 = 'set from MyClass: + str(v) def get_instance_value_1(self): return self.instance_value_1 class MyMixinclass_1: def set_instance_value_(self, v): self.instance_value_2 = 'set from MyMixinclass_1: + str(v) def get instance_value_2(self): return self.instance_value_2 def set_instance_value_4(self, v): self.instance_value_4 = 'set from MyMixinclass_1: + str (v) def get_instance_value_4(self): return self.instance_value_4 class MyMixinclass_2: def set_instance_value_3(self, v): self.instance_value_3 = 'set from MyMixinclass_2: ' + str(v) def get_instance_value_3(self): return self.instance_value_3 def set_instance_value_4(self, v): self.instance_value_4 = 'set from MyMixinclass_2: + str(v) def get instance_value_4(self): self.instance_value_4 I class MySubclass(MyMainclass, MyMixinclass_1, MyMixinclass_2): pass # *** *** confirming the class hierarchy *** *** print("MyMainclass\'s inheritance resolution order is ', object._class_. mro(MyMainclass)(1:] ) print("MyMainclass\'s primary superclass is ', MyMainclass._class___ _base_) subclasses = object._class_: __subclasses__(MyMainclass) if subclasses: print( 'MyMainclass\'s subclasses are ', subclasses ) else: print( 'MyMainclass has no subclasses' ) print('') print("MyMixinclass_1\'s inheritance resolution order is ', object._class_.mro (MyMixinclass_1)[1:] ) print( 'MyMixinclass_11's primary superclass is , MyMixinclass_1._class_-_base_) subclasses = object._class___subclasses__(MyMixinclass_1) if subclasses: print('MyMixinclass_1\'s subclasses are subclasses) else: print( 'MvMixinclass 1 has no subclasses' ) else: print('MyMixinclass_1 has no subclasses' ) print --') print("MyMixinclass_2\'s inheritance resolution order is ', object. class_.mro (MyMixinclass_2)[1:] ) print("MyMixinclass_21's primary superclass is ', MyMixinciass_2._class____base_) subclasses = object. _class___subclasses_(MyMixinclass_2) if subclasses: print( 'MyMixinclass_2\'s subclasses are ', subclasses ) else: print('MyMixinclass_2 has no subclasses' ) print(.. print("MySubclass\'s inheritance resolution order is ', object._class_.mro (Mysubclass)[1:] ) print("MySubclassl's primary superclass is ', MySubclass._class_u_base_) subclasses = object._class_ __subclasses_(MySubclass) if subclasses: print( 'MySubclass\'s subclasses are ', subclasses ) else: print('MySubclass has no subclasses' ) print('') # *** *** invoking final, mixin-based class methods *** *** my_subclass_instance = MySubclass() print('setting subclass value 1 to l'one\', 2 to l'two!', 3 to \'threel', and 4 to l'four\'') my_subclass_instance.set_instance_value_1('one') my_subclass_instance.set_instance_value_2"two") my_subclass_instance.set_instance_value_3("three') my_subclass_instance.set_instance_value_4('four') print() print( 'Retrieving the four values. Note that the two mixin classes each define a set method for value 4' ) print("value 1 is ', my_subclass_instance.get_instance_value_10 ) print( 'value 2 is my_subclass_instance.get_instance_value_20 ) print( 'value 3 is my_subclass_instance.get instance_value_30) print( 'value 4 is ; my_subclass_instance.get_instance_value_40) 2 Exercise: (1 point) In the following code cell, show the method resolution order for int and objectStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started