類和繼承——python經(jīng)典實(shí)例
提問人:楊紫紅發(fā)布時(shí)間: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))
'''
知識(shí)點(diǎn):
* self:類似Java的this參數(shù)
'''
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))
'''
知識(shí)點(diǎn):
* self:類似Java的this參數(shù)
'''
繼續(xù)查找其他問題的答案?
相關(guān)視頻回答
點(diǎn)擊加載更多評(píng)論>>