您的位置:首页 > 编程语言 > Python开发

8.Python基础 面向对象的基本概念

2015-08-09 19:03 656 查看
vamei前辈博客:

/article/4673211.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++同样具有属性和方法,有继承的属性,还有封装和多态属性吗?
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: