def __init__(self, num):
self.num=num
fibo=[0,1]
i=2
while i<self.num:
fibo.append(fibo[i-2]+fibo[i-1])
i = i+1
self.fibo=fibo
def __str__(self):
return str(self.fibo)
def __len__(self):
return len(self.fibo)
self.num=num
fibo=[0,1]
i=2
while i<self.num:
fibo.append(fibo[i-2]+fibo[i-1])
i = i+1
self.fibo=fibo
def __str__(self):
return str(self.fibo)
def __len__(self):
return len(self.fibo)
2018-03-15
if self.score < s.score:
return 1
elif self.score > s.score:
return -1
elif self.name < s.name:
return -1
elif self.name > s.name:
return 1
else:
return 0
return 1
elif self.score > s.score:
return -1
elif self.name < s.name:
return -1
elif self.name > s.name:
return 1
else:
return 0
2018-03-15
已采纳回答 / 慕丝5066221
再定义类的时候就执行了print,如果你把最后一个也屏蔽#s = BStudent(),也会把上边的定义类时的print执行掉。最后一行s = BStudent(),只是赋值行为,不会执行类,所以不会执行print
2018-03-15
# -*- coding: UTF-8 -*-
def get_grade(self):
if self.__score>=90:
return 'A-优秀'
elif self.__score>=60:
return 'B-及格'
else:
return 'C-不及格三档'
def get_grade(self):
if self.__score>=90:
return 'A-优秀'
elif self.__score>=60:
return 'B-及格'
else:
return 'C-不及格三档'
2018-03-15
def calc_prod(lst):
def lazy_prod():
prod = 1
for x in lst:
prod *= x
return prod
return lazy_prod
f = calc_prod([1, 2, 3, 4])
print f()
def lazy_prod():
prod = 1
for x in lst:
prod *= x
return prod
return lazy_prod
f = calc_prod([1, 2, 3, 4])
print f()
2018-03-15
def prod(x, y):
return x*y
print reduce(prod, [2, 4, 5, 7, 12])
return x*y
print reduce(prod, [2, 4, 5, 7, 12])
2018-03-15