1 Star 0 Fork 0

chengy/python_demo01

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
inhert.py 1.47 KB
一键复制 编辑 原始数据 按行查看 历史
chengy 提交于 2019-02-15 11:47 . init commit
#!/usr/bin/env python3
# _*_ coding:utf-8 _*_
'多重继承'
__author__ = 'chenguangyue'
class Animal(object):
pass
# 大类
class Mammal(Animal):
pass
class Runable(object):
def run(self):
print('Running...')
class Flyable(object):
def fly(self):
print('flying...')
class Bird(Animal):
pass
# 各种动物
class Dog(Mammal, Runable):
pass
class Bat(Mammal, Flyable):
pass
class Parrot(Bird):
pass
class Ostrich(Bird):
pass
class Fib(object):
def __init__(self):
self.a, self.b = 0, 1 # 初始化两个计数器a,b
def __iter__(self):
return self
def __next__(self):
self.a, self.b = self.b, self.a + self.b
if self.a > 100000:
raise StopIteration()
return self.a
def __getitem__(self, item):
if isinstance(item, int):
a, b = 1, 1
for x in range(item):
a, b = b, a + b
return a
if isinstance(item, slice):
start = item.start
stop = item.stop
if start is None:
start = 0
a, b = 1, 1
L = []
for x in range(stop):
if x >= start:
L.append(x)
a, b = b, a + b
return L
def __getattr__(self, item):
if item == 'name':
return 'fib'
f = Fib()
print(f.name)
print(f[3])
print(f[3:5])
# for n in Fib():
# print(n)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/nocoding/python_demo01.git
[email protected]:nocoding/python_demo01.git
nocoding
python_demo01
python_demo01
master

搜索帮助