类和继承——python经典实例
提问人:杨紫红发布时间:2020-11-26
class Base:
def __init__(self):
self.data = []
def add(self, x):
self.data.append(x)
def addtwice(self, x):
self.add(x)
self.add(x)
# Child extends Base
class Child(Base):
def plus(self,a,b):
return a+b
oChild =Child()
oChild.add("str1")
print (oChild.data)
print (oChild.plus(2,3))
'''
知识点:
* self:类似Java的this参数
'''
def __init__(self):
self.data = []
def add(self, x):
self.data.append(x)
def addtwice(self, x):
self.add(x)
self.add(x)
# Child extends Base
class Child(Base):
def plus(self,a,b):
return a+b
oChild =Child()
oChild.add("str1")
print (oChild.data)
print (oChild.plus(2,3))
'''
知识点:
* self:类似Java的this参数
'''
继续查找其他问题的答案?
相关视频回答
回复(0)
点击加载更多评论>>