在寫python繼承的時候突然想到,繼承的時候子類的self是否繼承了父類的self,于是嘗試了一下:
class foo(object):
def add(self,strin):
self.strin=strin
def say(self):
print "string is : %s" % self.strin
class bar(foo):
def saybar(self):
print "Created By Bar , i say : %s " % self.strin
b=bar()
b.add('hello')
b.say()
b.saybar()
運行結果如下:
string is : hello
Created By Bar , i say :hello