且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

类的继承_子类继承父类

更新时间:2022-04-03 02:04:12

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