reference: https://www.zhihu.com/question/27699413/answer/267906889

摘要:

我们在描述一个真实对象(物体)时包括两个方面:
它可以做什么(行为)
它是什么样的(属性或特征)
结论:对象=属性(特征)+方法(行为)
相同属性和方法的对象归为一个类(class)


reference:https://www.codementor.io/sheena/essential-python-interview-questions-du107ozr6#
class A(object):
def go(self):
print("go A go!")
def stop(self):
print("stop A stop!")
def pause(self):
raise Exception("Not Implemented") class B(A):
def go(self):
super(B, self).go()
print("go B go!") class C(A):
def go(self):
super(C, self).go()
print("go C go!")
def stop(self):
super(C, self).stop()
print("stop C stop!") class D(B,C):
def go(self):
super(D, self).go()
print("go D go!")
def stop(self):
super(D, self).stop()
print("stop D stop!")
def pause(self):
print("wait D wait!") class E(B,C): pass a = A()
b = B()
c = C()
d = D()
e = E() # specify output from here onwards a.go()
b.go()
c.go()
d.go()
e.go() a.stop()
b.stop()
c.stop()
d.stop()
e.stop() a.pause()
b.pause()
c.pause()
d.pause()
e.pause()
# output:
a.go()
# go A go! b.go()
# go A go!
# go B go! c.go()
# go A go!
# go C go! d.go()
# go A go!
# go C go!
# go B go!
# go D go! e.go()
# go A go!
# go C go!
# go B go! a.stop()
# stop A stop! b.stop()
# stop A stop! c.stop()
# stop A stop!
# stop C stop! d.stop()
# stop A stop!
# stop C stop!
# stop D stop! e.stop()
# stop A stop! a.pause()
# ... Exception: Not Implemented b.pause()
# ... Exception: Not Implemented c.pause()
# ... Exception: Not Implemented d.pause()
# wait D wait! e.pause()
# ...Exception: Not Implemented

python note of class的更多相关文章

  1. python note

    =和C一样,为赋值.==为判断,等于.但是,在python中是不支持行内赋值的,所以,这样避免了在判断的时候少写一个出错. dictionary 的key唯一,值可以为很多类型. list的exten ...

  2. python note 4

    1.使用命令行打开文件 t=open('D:\py\123.txt','r') t.read() 在python和很多程序语言中""转义符号,要想输出\要么多加一个\写成\ 要么在 ...

  3. python note 17 random、time、sys、os模块

    1.random模块(取随机数模块) # 取随机小数 : 数学计算 import random print(random.random())# 取0-1之间的小数 print(random.unifo ...

  4. python note 16 re模块的使用

    1.re模块(#regex) # 查找 # findall : 匹配所有 每一项都是列表中的一个元素 import re ret = re.findall('\d+','dawdawd154wadwa ...

  5. python note 15 正则表达式

    # 正则表达式 只和字符串打交道 # 正则表达式的规则# 规则 字符串 从字符串中找到符合规则的内容 # 字符组 : [] 写在中括号中的内容,都出现在下面的某一个字符的位置上都是符合规则的 # [0 ...

  6. python note 12 生成器、推导式

    1.生成器函数 # 函数中如果有yield 这个函数就是生成器函数. 生成器函数() 获取的是生成器. 这个时候不执行函数# yield: 相当于return 可以返回数据. 但是yield不会彻底中 ...

  7. python note 10 函数变量

    1.命名空间 #内置命名空间 —— python解释器 # 就是python解释器一启动就可以使用的名字存储在内置命名空间中 # 内置的名字在启动解释器的时候被加载进内存里#全局命名空间 —— 我们写 ...

  8. python note 01 计算机基础与变量

    1.计算机基础. 2.python历史. 宏观上:python2 与 python3 区别: python2 源码不标准,混乱,重复代码太多, python3 统一 标准,去除重复代码. 3.pyth ...

  9. python note of decorator

    def decorate_log(decorate_arg,*args,**kwargs): # 存放装饰器参数 def decorate_wrapper(func,*args,**kwargs): ...

  10. python note #1

    To record my process of studying python and to practice my English meanwhile, I'd like to start writ ...

随机推荐

  1. bzoj 4571 美味 —— 主席树

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4571 区间找异或值最大,还带加法,可以用主席树: 可以按位考虑,然后通过加上之前已经有的答案 ...

  2. 前端之html第一天

    一.内容

  3. Day.js 是一个仅 2kb 大小的轻量级 JavaScript 时间日期处理库,和 Moment.js 的 API 设计保持完全一样,dayjs

    https://gitee.com/mirrors/Day.js api: https://gitee.com/mirrors/Day.js/blob/master/docs/zh-cn/API-re ...

  4. Excel:一列是源值随机加减某随机值,变为另一列的数值

    1) 产生x1与x2之间整数随机数 =RANDBETWEEN(x1,x2),x1和x2为随机数区间 如果需要小数,可以乘以小数获得,Eg: =RANDBETWEEN(-5,5)*0.01,表示 -0. ...

  5. python 高阶函数三 filter()和sorted()

    一.filter()函数 filter()接收一个函数和一个序列.filter()把传入的函数依次作用于每个元素,然后根据返回值是True还是False决定保留还是丢弃该元素. >>> ...

  6. bzoj 4481: [Jsoi2015]非诚勿扰【期望+树状数组】

    首先很容易计算对于一个如意郎君列表里有x个男性的女性,编号排第i位的男性被选的概率是 \[ p*(1-p)^{i-1}+p*(1-p)^{i-1+n}+p*(1-p)^{i-1+n}+- \] \[ ...

  7. (8)css表格

    用css设置表格样式 *<table></table> 标签定义 HTML 表格. * tr 元素定义表格的行:th 元素定义表格的表头:td 元素定义表格中的单元格:capt ...

  8. Android UI 设计规范

    1. 基础常识 1.1 主流屏幕尺寸 标识 屏幕尺寸 hdpi 480 * 800 xhdpi 720 * 1280 xxhdpi 1080 * 1920 1.2 图标尺寸 标识 启动图标尺寸 菜单图 ...

  9. IIS发布问题服务器配置

    1. <validation validateIntegratedModeConfiguration="false" /> 2.Http 404.0-NotFound ...

  10. [USACO 2011 Nov Gold] Above the Median【逆序对】

    传送门:http://www.usaco.org/index.php?page=viewproblem2&cpid=91 这一题我很快的想出了,把>= x的值改为1,< x的改为- ...