在写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