8.Python基础 面向对象的基本概念
2015-08-09 19:03
656 查看
vamei前辈博客:
/article/4673211.html
自己的学习笔记:
和C++同样具有属性和方法,有继承的属性,还有封装和多态属性吗?
/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++同样具有属性和方法,有继承的属性,还有封装和多态属性吗?
相关文章推荐
- Python-Selenium2做Web自动化测试(11)-下拉框处理、分页处理
- Python-Selenium2做Web自动化测试(10)-浏览器多窗口处理、alert/confirm/prompt 处理
- Python-Selenium2做Web自动化测试(9)-定位Frame中的对象、对话框处理
- Python-Selenium2做Web自动化测试(8)-定位一组对象以及层级定位
- python爬虫抓取LeetCode题目
- python计算数组中对象出现的次数并且按照字典输出
- Python[小甲鱼003小插曲之变量和字符串]
- Python[小甲鱼-002用Python设计第一个游戏]
- Python[小甲鱼007了不起的分支和循环]
- Python[小甲鱼006常用操作符]
- Python[小甲鱼005Python的数据类型]
- python根据京东商品url获取产品价格
- 基本的Python的正则表达式
- python制作一个桌面便签软件
- Python 实现简单的电话本功能
- 【已解决】Python脚本运行出现语法错误:IndentationError: unindent does not match any outer indentation level
- 【Python】序列的方法
- 零基础学python-1.4 hello world
- 零基础学python-1.4 hello world
- Python中re(正则表达式)模块详解