@property,可以将python定义的函数“当做”属性访问,从而提供更加友好访问方式
课程最好能多解释一下作用,而不是直接写使用方法
课程最好能多解释一下作用,而不是直接写使用方法
2015-03-17
for ck in sorted(range(min(self.p, self.q)+1), reverse = True):
if self.p % ck == 0 and self.q % ck == 0:
self.p = self.p / ck
self.q = self.q / ck
break
return '%s/%s' % (self.p, self.q)
if self.p % ck == 0 and self.q % ck == 0:
self.p = self.p / ck
self.q = self.q / ck
break
return '%s/%s' % (self.p, self.q)
2015-03-17
生成数列:
def __init__(self, num):
if num == 1:
self.fib = [0]
else:
self.fib = [0,1]
while num != 2 :
self.fib.append(self.fib[-2]+self.fib[-1])
num = num - 1
def __init__(self, num):
if num == 1:
self.fib = [0]
else:
self.fib = [0,1]
while num != 2 :
self.fib.append(self.fib[-2]+self.fib[-1])
num = num - 1
2015-03-17