5. Multiple Inheritance and What Object is It?

1class Ethernet:
2    def __init__(self, name, mac_address):
3        self.name = name
4        self.mac_address = mac_address
5
6
7class Wireless(Ethernet):
8    def __init__(self, name, mac_address):
9        Ethernet.__init__(self, name, mac_address)
10
11
12class PCI:
13    def __init__(self, bus, manufacturer):
14        self.bus = bus
15        self.manufacturer = manufacturer
16
17
18class USB:
19    def __init__(self, device):
20        self.device = device
21
22
23class PCIEthernet(PCI, Ethernet):
24    def __init__(self, bus, manufacturer, name, mac_address):
25        PCI.__init__(self, bus, manufacturer)
26        Ethernet.__init__(self, name, mac_address)
27
28
29class USBWireless(USB, Wireless):
30    def __init__(self, device, name, mac_address):
31        USB.__init__(self, device)
32        Wireless.__init__(self, name, mac_address)
33
34
35wlan0 = USBWireless("usb0", "wlan0", "00:33:44:55:66")
36eth0 = PCIEthernet("pci :0:0:1", "realtek", "eth0", "00:11:22:33:44")
37
38
39print(isinstance(wlan0, Ethernet))
40print(isinstance(eth0, PCI))
41print(isinstance(eth0, USB))
line that just executed

next line to execute

Print output (drag lower right corner to resize)
Frames
Objects

Activity: CodeLens 5.1 (cl_l25_5_en)

On a scale from 1 (needs improvement) to 3 (excellent), how would you rate this chapter?




Activity: 5.2 Poll (TWP25E)

You have attempted 1 of 3 activities on this page