python 类继承 父类初始化_python类继承,父类和子类的构造函数初始化调用-阿里云开发者社区...

# class Info(object):

# def __init__(self,name,age,score):

# self.Name = name

# self.Age = age

# self.Score = score

#

#

# class Student(object):

# def __init__(self,info):

# self.Info = info

#

# # Home = "地球"

# # __Sxt = "女"

# #

# # def GetSex(self):

# # return Student.__Sxt

# #

# # def __init__(self,name,age,score,comp):

# # self.Name = name

# # self.Age = age

# # self.Score = score

# # self.__Comp = comp

# #

# # def GetComp(self):

# # return self.__Comp

# #

# # def SetComp(self,comp):

# # self.__Comp = comp

#

# # stu = Student("gou",21,98)

# #

# # stu.Home = "火星"

# # print(stu.Home)

# # print(stu.__class__.Home)

# # print(Student.Home)

#

# # stu1 = Student("a",11,33,"mac")

# # print(stu1.GetComp())

# # stu1.SetComp("deal")

# # print(stu1.GetComp())

# #

# # print(stu1.GetSex())

#

# # info = Info("a",18,98)

# stu = Student(Info("a",18,98))

#

# print(type(stu))

# print(type(stu.Info))

# print(stu.Info.Name)

# 信息基类

class MemberInfo(object):

__name = None

__age = None

__score = None

def __init__(self,name,age,score):

print("parent init")

self.__name = name

self.__age = age

self.__score = score

def GetName(self):

return self.__name

class Student(MemberInfo):

def __init__(self,name,age,score,comp):

MemberInfo.__init__(self,name,age,score)

print("child init")

self.__Comp = comp

def GetComp(self):

return self.__Comp

#

# # stu = Student("a",15,98)

# stu = Student("mac")

# print(stu.GetComp())

stu = Student("gou",18,98,"mac")

print(stu.GetName())

print(stu.GetComp())

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值