python支持多重继承

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

上一篇:mPaas移动推送常见问题和踩坑记录


下一篇:谁将成为欧洲首个5G城市? 多家运营商加速5G步伐