华南俳烁实业有限公司

python

當(dāng)前位置:中華考試網(wǎng) >> python >> python教程 >> 文章內(nèi)容

python3父類需要繼承object嗎?

來源:中華考試網(wǎng)  [2020年11月16日]  【

  在傳統(tǒng)的開發(fā)中,初始化父類一般使用的是子類直接調(diào)用父類的_init__方法:

  1

  2

  3

  4

  5

  6

  7

  8

  9

  10

  11

  12

  13

  14

  15

  16

  17

  class first(object):

  def __init__(self,value):

  self.value = value

  class son_of_first(first):

  def __init__(self):

  first.__init__(self,9)

  對于初學(xué)者建立的繼承體系,是沒有問題的,也是最普遍的做法

  class fatherclass(object):

  def __init__(self):

  self.value += 1

  class fatherclass2(object):

  def __init__(self):

  self.value *= 1

  class way(fatherclass,fatherclass2):

  def __init__(self,value):

  fatherclass.__init__(self)

  fatherclass2.__init__(self)

  在以上類中,最后在參數(shù)入口傳入的是什么順序的類,最后執(zhí)行的就是什么順序的類

python課程免費試聽預(yù)約

  • 地區(qū):
  • 姓名:
  • 手機:

  例如以下的類定義順序與產(chǎn)生結(jié)果就是不同的:

  1

  2

  3

  4

  5

  6

  7

  8

  9

  10

  class fatherclass(object):

  def __init__(self):

  self.value += 1

  class fatherclass2(object):

  def __init__(self):

  self.value *= 1

  class way(fatherclass2,fatherclass1):

  def __init__(self,value):

  fatherclass.__init__(self)

  fatherclass2.__init__(self)

  整篇文章看完的小伙伴已經(jīng)知道答案了,這里小編為大家揭曉父類是可以不繼承的。

責(zé)編:fushihao
  • 會計考試
  • 建筑工程
  • 職業(yè)資格
  • 醫(yī)藥考試
  • 外語考試
  • 學(xué)歷考試
响水县| 舒城县| 新竹市| 吉林市| 象山县| 赣榆县| 加查县| 大庆市| 永昌县| 德州市| 怀安县| 宝丰县| 楚雄市| 嫩江县| 桑植县| 鸡西市| 和平县| 青浦区| 望谟县| 林口县| 荆门市| 甘洛县| 潜江市| 商水县| 胶州市| 汕尾市| 和龙市| 乐都县| 高雄市| 贵州省| 建湖县| 永靖县| 泰和县| 广宗县| 临湘市| 页游| 衡阳县| 东台市| 玉林市| 拉萨市| 甘洛县|