vamei前辈博客:
http://www.cnblogs.com/vamei/archive/2012/06/02/2531515.html
自己的学习笔记:
#!/usr/bin/python
class Bird(object): #Bird类继承之object,object是各个类的父类
have_feather = True
way_of_reproduction = 'egg'
def move(self, dx, dy): #行为方法:move,第一个参数必须是self,其实改成xx也能运行
position = [0, 0] #self是供内部使用的
position[0] += dx
position[1] += dy
return position
summer = Bird()
print (summer.way_of_reproduction)
print ('after move:',summer.move(5, 6))
class Chicken(Bird): #Chicken继承之Bird,它有Bird的所有属性
way_of_move = 'walk' #又增加了way_of_move和possible_in_KFC属性
possible_in_KFC = True
class Oriole(Bird):
way_of_move = 'fly'
possible_in_KFC = False
summer = Chicken()
print (summer.have_feather)
print (summer.move(5, 8))
和C++同样具有属性和方法,有继承的属性,还有封装和多态属性吗?