代码拉取完成,页面将自动刷新
#!/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)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。