美食网站建设书,类似淘宝网 的淘宝客网站模板,深圳制作网站流程,网站开发入无形资产摊销几年一、基础知识
#xff08;一#xff09;定义#xff1a;子类能继承父类所有的公有属性和公有方法#xff08;先使用子类的方法、属性#xff09;
#xff08;二#xff09;格式#xff1a;
class 子类名#xff08;父类名#xff09;#xff1a;
#父类
class Ph…一、基础知识
一定义子类能继承父类所有的公有属性和公有方法先使用子类的方法、属性
二格式
class 子类名父类名
#父类
class Phone():def phone_call(self,number):print(f正在给{number}打电话)
#子类
class Iphone(Phone):def carmera(self):print(正在拍照)phoneIphone()
phone.carmera()
phone.phone_call(1345678345)
#结果
正在拍照
正在给1345678345打电话
二、在子类中间接调用父类私有属性和私有方法
#父类
class Phone():#父类私有方法def __number(self,number):self.list1 [number]print(self.list1)def phone_call(self):print(正在给打电话)#子类无法直接修改父类私有方法但可以间接调用self.__number(100867)
#子类
class Iphone(Phone):def carmera(self):print(正在拍照)def show_number(self):self.phone_call()#此时调用了父类的私有方法phoneIphone()
phone.show_number()
#结果
正在给打电话
[100867]