- 帖子
- 6
- 精华
- 0
- 积分
- 25
- 阅读权限
- 10
- 注册时间
- 2022-8-28
- 最后登录
- 2022-12-17
|
类的单继承运行正常,代码如下:
class Phone:
IMEI = None # 序列号
producer = 'Buddy' # 厂商
def call_by_4G(self):
print('4G通话状态。')
class Phone2022(Phone):
face_id = '1001'
def call_by_5G(self):
print('2022年新功能:5G通话。')
phone = Phone2022()
print(phone.producer)
phone.call_by_4G()
phone.call_by_5G()
但是多继承运行出错,代码如下:
class Phone:
IMEI = None # 序列号
producer = 'Buddy' # 厂商
def call_by_4G(self):
print('4G通话状态。')
class NFCReader:
nfc_type = '第五代'
producer = 'Buddy' # 厂商
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.call_by_4G()
phone.read_card()
phone.write_card()
phone.control()
出错提示:
C:\Users\Administrator\AppData\Local\Programs\Python\Python38\python.exe C:/Users/Administrator/PycharmProjects/pythonProject2/类/10_类的多继承.py
Traceback (most recent call last):
File "C:/Users/Administrator/PycharmProjects/pythonProject2/类/10_类的多继承.py", line 28, in <module>
phone.call_by_4G()
TypeError: call_by_4G() missing 1 required positional argument: 'self'
请教是什么原因?
|
|