0
這些是我的結果,我需要myClass method1在調用c2.method1()時再次返回。 (Python 3)我會怎麼做呢?我正在使用的教程說,調用c2.method1應在第四行結果中產生最後一行「anotherClass method1」以及「myClass method1」。如何從父類調用方法Python 3
myClass method1
myClass method2: This is a string
anotherClass method1
這是代碼。
class myClass():
def method1(self):
print("myClass method1")
def method2(self, someString):
print("myClass method2: " + someString)
class anotherClass(myClass):
def method2(self):
print("anotherClass method2")
def method1(self):
print("anotherClass method1")
def main():
c = myClass()
c.method1()
c.method2("This is a string")
c2 = anotherClass()
c2.method1()
main()
「的教程中,我使用」哪一個? 「說」哪裏? –
顯示的輸出是正常行爲。如果您需要調用超類的方法,請使用'super()'(詳細信息請閱讀文檔)。 –