class Animal:
def __init__(self, name): # Constructor of the class
self.name = name
def talk(self): # Abstract method, defined by convention only
raise NotImplementedError("Subclass must implement abstract method") class Cat(Animal):
def talk(self):
return 'Meow!' class Dog(Animal):
def talk(self):
return 'Woof! Woof!' animals = [Cat('Missy'),
Cat('Mr. Mistoffelees'),
Dog('Lassie')] for animal in animals:
print animal.name + ': ' + animal.talk() # prints the following:
#
# Missy: Meow!
# Mr. Mistoffelees: Meow!
# Lassie: Woof! Woof!

  

最新文章

  1. BZOJ的两道osu概率DP easy与osu
  2. Struts2 有关于无法正常的使用通配符
  3. Java集合系列:-----------05LinkedList的底层实现
  4. java-数字类
  5. 用JAVA代码实现验证邮箱地址是否符合
  6. 第四课 Gallery的使用
  7. CSS font-family的順序
  8. PHP - 数学运算
  9. Webx3学习笔记(2)——基本流程
  10. 在vue 中使用Stylus
  11. 用系统为centos6的主机,搭建PXE服务器,实现批量安装centos6,7系统
  12. 13. Redis监控运维云平台CacheCloud
  13. Log4j配置记录
  14. Python大神成长之路: 第二次学习记录
  15. linux计划任务之crontab
  16. #ZLYD团队第二周项目总结
  17. day 90 DjangoRestFramework学习二之序列化组件
  18. Jquery chosen动态设置值 select Ajax动态载入数据 设置chosen和获取他们选中的值
  19. Generator 函数的异步应用
  20. 基于Python-Flask实现的网站例子

热门文章

  1. rabbitma客户端
  2. [python 学习] 类
  3. LOJ2540「PKUWC2018」随机算法
  4. 图片公式转为word格式
  5. 【leetcode】1046. Last Stone Weight
  6. Vue项目【饿了么App】mock数据【data.json】
  7. Bugku 杂项 这是一张单纯的图片
  8. 如何安全修改cocoapods上的第三方代码
  9. Hibernate入门学习笔记
  10. python 数字系列-无穷大与NaN