有关访问父类的实例成员
我写了下列代码
3 class First(object):
4 aa = "class"
5 def __init__(self):
6 self.aa = 3
7 print 'This is First init'
8
9
10 class Third(First):
11 def __init__(self):
12 self.aa = 4
13 First.__init__(self)
14 print "This is Third init"
15 def show(self):
16 print self.aa
17 print First.aa
18 th = Third()
19 th.show()
...
class Third(First):
def __init__(self):
self.aa = 4
First.__init__(self) #这块是父类改写子类的aa
print "This is Third init"
def show(self):
print self.aa#打印出来的是父类的值self.aa=3
print First.aa
th = Third()#子类对象
th.show()
class First(object):
aa = "class"
def __init__(self):
self.aa = 3
print 'This is First init'
class Third(First):
def __init__(self):
self.aa = 4
# First.__init__(self)
print "This is Third init"
def show(self):
print self.aa
print First.aa
print First().aa
th = Third()
th.show()