python中有类似C++的多重继承,这个特性为Java,Delphi,VB等所不具有的,应予以重视
*** Python 2.4.3 (#69, Mar 29 2006, 17:35:34) [MSC v.1310 32 bit (Intel)] on win32. ***
>>> class A:
... name='A'
... _num=1
... def show(self):
... print self.name
... print self._num
... def setnum(self,num):
... self._num=num
...
>>> class B:
... nameb='B'
... _numb=2
... def show(self):
... print self.nameb
... print self._numb
... def setname(self,name):
... self.nameb=name
...
>>> class C(A,B):
... def showall(self):
... print self.name
... print self.nameb
...
>>> c=c()
Traceback (most recent call last):
File "<interactive input>", line 1, in ?
NameError: name 'c' is not defined
>>> c=C()
>>> c.show()
A
1
>>> c.setnum(3)
>>> c.show()
A
3
>>> c.setname('D')
>>> c.showall()
A
D
>>>