摘要: #!/usr/local/bin/python3 # -*- coding:utf-8 -*- ''' 多态的作用:实现接口的重用 ''' class Animal(object): def __init__(self, name): self.name = name print("i am %s" % self.name) def anima... 阅读全文
posted @ 2018-05-20 21:41 Octopuslnlzy 阅读(132) 评论(0) 推荐(0) 编辑
摘要: #!/usr/local/bin/python3 # -*- coding:utf-8 -*- ''' 构造方法继承策略: 在python2中,经典类是按照深度优先继承构造方法的;新式类是按照广度优先继承构造方法的 在python3中,经典类和新式类都是按照广度优先继承构造方法的 ''' class A(object): def __init__(self): ... 阅读全文
posted @ 2018-05-20 21:40 Octopuslnlzy 阅读(342) 评论(0) 推荐(0) 编辑
摘要: #!/usr/local/bin/python3 # -*- coding:utf-8 -*- class Role(object): n = 123 # 类变量 name = "我是类name" def __init__(self, name, role, weapon, life_value=100, money=15000): # 构造函数 ... 阅读全文
posted @ 2018-05-20 21:38 Octopuslnlzy 阅读(1172) 评论(0) 推荐(0) 编辑
摘要: #!/usr/local/bin/python3 # -*- coding:utf-8 -*- # class People: #经典类 class People(object): #新式类,此处的object是基类,People继承object def __init__(self, name, age): self.name = name self.a... 阅读全文
posted @ 2018-05-20 21:37 Octopuslnlzy 阅读(153) 评论(0) 推荐(0) 编辑