119子类依旧使用父类的属性和方法

 

 

class Phone:
    producer="IT"
    def call_by_5g(self):
        print("父类使用5g网络进行通话")
# 定义子类
class MyPhone(Phone):
    producer = 'TO'
    def call_by_5g(self):
        print("自己的手机")
        print(f"父类的厂商:{super().producer}")
        super().call_by_5g()
        print("-----------")
phone1=MyPhone()
phone1.producer
phone1.call_by_5g()
'''
自己的手机
父类的厂商:IT
父类使用5g网络进行通话
-----------
'''

 

posted @ 2023-07-06 21:50  胖豆芽  阅读(3)  评论(0编辑  收藏  举报