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() # 说明下列代码的输出结果 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()

答案

输出结果以注释的形式表示:

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中super函数的用法。

本文首发于Python黑洞网,博客园同步跟新

python面试题之阅读下面的代码,它的输出结果是什么?的更多相关文章

  1. Python面试题之阅读下面的代码,写出A0,A1至An的最终值

    A0 = dict(zip(('a','b','c','d','e'),(1,2,3,4,5))) A1 = range(10) A2 = [i for i in A1 if i in A0] A3 ...

  2. python面试题之补充缺失的代码

    补充缺失的代码 def print_directory_contents(sPath): """ 这个函数接受文件夹的名称作为输入参数, 返回该文件夹中文件的路径, 以及 ...

  3. 常见python面试题-手写代码系列

    1.如何反向迭代一个序列 #如果是一个list,最快的方法使用reversetempList = [1,2,3,4]tempList.reverse()for x in tempList:    pr ...

  4. python公司面试题集锦 python面试题大全

    问题一:以下的代码的输出将是什么? 说出你的答案并解释. class Parent(object): x = 1 class Child1(Parent): pass class Child2(Par ...

  5. Python面试题之Python面试题汇总

    在这篇文章中: Python基础篇 1:为什么学习Python 2:通过什么途径学习Python 3:谈谈对Python和其他语言的区别 Python的优势: 4:简述解释型和编译型编程语言 5:Py ...

  6. 最新Python笔试题2017 涵盖知识面广泛

    引言 想找一份Python开发工作吗?那你很可能得证明自己知道如何使用Python.下面这些问题涉及了与Python相关的许多技能,问题的关注点主要是语言本身,不是某个特定的包或模块.每一个问题都可以 ...

  7. python 面试题4

    Python面试题 基础篇 分类: Python2014-08-08 13:15 2071人阅读 评论(0) 收藏 举报 最近,整理了一些python常见的面试题目,语言是一种工具,但是多角度的了解工 ...

  8. 震惊!几道Python 理论面试题,Python面试题No18

    本面试题题库,由公号:非本科程序员 整理发布 第1题: 简述解释型和编译型编程语言? 解释型语言编写的程序不需要编译,在执行的时候,专门有一个解释器能够将VB语言翻译成机器语言,每个语句都是执行的时候 ...

  9. 常见的 35 个 Python 面试题及答案

    1. Python 面试问题及答案 作为一个 Python 新手,你必须熟悉基础知识.在本文中我们将讨论一些 Python 面试的基础问题和高级问题以及答案,以帮助你完成面试.包括 Python 开发 ...

随机推荐

  1. luoguP1079 Vigenère 密码 题解(NOIP2012)

    P1079 Vigenère 密码 题目 #include<iostream> #include<cstdlib> #include<cstdio> #includ ...

  2. make源文件时出现 /usr/bin/ld: cannot find -lstdc++ 错误

    解决CentOS 7 中,make源文件时出现 /usr/bin/ld: cannot find -lstdc++ 错误 在CentOS 7中,使用static方法编译,需要安装static vers ...

  3. form 表单的name

    form 中 的name 很重要, 1. 可以用来查找对应的input 2.form 提交之后 会用来作为参数列表的名字 3.enovia plm 中,name 会和 table 的field 进行对 ...

  4. java 多线程间通信(二)

    传统的线程通信 Object提供了三个方法wait(), notify(), notifyAll()在线程之间进行通信,以此来解决线程间执行顺序等问题. wait():释放当前线程的同步监视控制器,并 ...

  5. 针对类别的5中softmax_cross_entropy loss计算

    # ---------------------------- #! Copyright(C) 2019 # All right reserved. # 文件名称:xxx.py # 摘 要:五种方式实现 ...

  6. map hashmap的使用

    package map; import java.util.HashMap; import java.util.Iterator; import java.util.Map; /** * Map的实现 ...

  7. day13 python生成器函数 推导式 生成器

    day13 python   一.生成器     生成器的本质就是迭代器     生成器的特点和迭代器一样. 取值方式和迭代器一样(__next__())     由生成器函数或生成器表达式来创建   ...

  8. 【QT学习】数独游戏

    前几天刷leetcode刷到一题,讲sudokuSolver,写完感觉很有意思,遂想做一个数独游戏,百度了一下如何自动生成题库,参考某位大神安卓下的实现思路,自己做了一套文字版的数独游戏,后来想乘机会 ...

  9. python 常用技巧 — 列表(list)

    目录: 1. 嵌套列表对应位置元素相加 (add the corresponding elements of nested list) 2. 多个列表对应位置相加(add the correspond ...

  10. iter()(一)

    >>> f=open('script2.py') >>> f <_io.TextIOWrapper name='script2.py' mode='r' en ...