最赞回答 / 慕粉9509213
你这个问题提的蛮不错的。暂时解决不了,但是有几点你可以参考一哈。对于第一个问题:可以说成是覆盖,因为调出来的是装饰之后的属性,不是你定义的实例属性。也可以说成不是覆盖,换言...
2018-01-29
from os.path import isdir, isfile
print isdir(r'/data/webroot/conf')
print isfile(r'/data/webroot/conf/app.conf')
print isdir(r'/data/webroot/conf')
print isfile(r'/data/webroot/conf/app.conf')
2018-01-29
import math
def is_sqr(x):
return math.sqrt(x) in range(1, 11)
print filter(is_sqr, range(1, 101))
def is_sqr(x):
return math.sqrt(x) in range(1, 11)
print filter(is_sqr, range(1, 101))
2018-01-29
最赞回答 / qq_8爷_0
列表fs经过append操作后加入的实际上是闭包g对象,而闭包g对象的真正返回值已经在r=f(i)过程中计算出来了,换句话说闭包g对象脱离了引用外部方法count()的局部变量。所以f1,f2,f3都是闭包g对象,而f1(),f2(),f3()执行后返回的是g(1),g(2),g(3)的值。
2018-01-28
def __call__(self, num):
'''
L = [0,1]
for i in range(num-2):
L.append(L[-1] + L[-2])
print(L)
'''
a, b, L = 0, 1, []
for i in range(num):
L.append(a)
a, b = b, a+b
print(L)
'''
L = [0,1]
for i in range(num-2):
L.append(L[-1] + L[-2])
print(L)
'''
a, b, L = 0, 1, []
for i in range(num):
L.append(a)
a, b = b, a+b
print(L)
2018-01-28
__slots__ = ('score')
def __init__(self, name, gender, score):
super(Student, self).__init__(name, gender)
self.score = score
def __init__(self, name, gender, score):
super(Student, self).__init__(name, gender)
self.score = score
2018-01-28
@property
def grade(self):
if self.__score >= 80:
return 'A'
elif self.__score >= 60:
return 'B'
else:
return 'C'
def grade(self):
if self.__score >= 80:
return 'A'
elif self.__score >= 60:
return 'B'
else:
return 'C'
2018-01-28