标签:color 扩展 tcl init people like 执行 方法 私有属性
3.1/3.2 类的继承
3.3 类的属性总结
3.4 类的方法总结
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‘)
pass
cn = Chinese()
print(cn.color)
print(cn.dwell)
cn.think()
class A(Object):
def __init__(self):
print ("enterA")
print ("leaveA")
class B(A):
def __init__(self):
print ("enetrB")
super(B,self).__init__()
print ("leaveB")
b = B()
###############
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):
super(Chinese, self).__init__(‘red‘)
pass
cn = Chinese()
class People (object):
def __init__(self):
self.dwell = ‘Earth‘
self.color = ‘yellow‘
def think(self):
print("I am a %s"%self.color)
print("My home is %s"%self.dwell)
class Martian(object):
color = ‘red‘
def __init__(self):
self.dwell = ‘Martian‘
def talk(self):
print("I LIKE")
class Chinese(Martian,People):
def __init__(self):
People.__init__(self)
cn = Chinese()
cn.think()
cn.talk()
标签:color 扩展 tcl init people like 执行 方法 私有属性
原文地址:http://blog.51cto.com/13542406/2059858