類的繼承_子類繼承父類

小周啊發表於2019-05-13

[root@blackfox zhouyuyao]# cat c5.py 

#!/usr/bin/python

#coding:utf-8

class People(object):

    color = `yellow`

    def __init__(self,c):

        print “Init…”

        self.dwell=`Earth`

    def think(self):

        print “I am a %s” % self.color

        print “I am a thinker.”

class Chinese(People):

    def __init__(self):

#        People.__init__(self,`red`)

        super(Chinese,self).__init__(`red`)         //super函式

    pass

cn=Chinese()

[root@blackfox zhouyuyao]# python c5.py 

Init…


相關文章