# 单继承
class Phone:
IMEI = None
producer = "HM"
def call_by_4G(self):
print("4G通话")
class Phone2022(Phone):
face_id = "10001"
def call_by_5G(self):
print("4G通话")
# 单继承
phone = Phone2022()
print(phone.producer)
phone.call_by_5G()
phone.call_by_4G()
# 多继承
class NFCReader:
nfc_type = "第五代"
producer = "jj"
def read_card(self):
print("NFC读卡")
def write_card(self):
print("NFC写卡")
class RemoteControl:
rc_type = "红外遥控"
def control(self):
print("红外开启了")
# 多继承 相同的成员变量和方法是按照从左到右的优先级
class myPhone(Phone, NFCReader, RemoteControl):
pass # 语法补全 表示这里是空的
phone=myPhone()
phone.read_card()
phone.control()
print(phone.producer)
运行结果:
HM
4G通话
4G通话
NFC读卡
红外开启了
HM