__slots__ = ('score')
def __init__(self, name, gender, score):
super(Person,self).__init__()
self.score = score
def __init__(self, name, gender, score):
super(Person,self).__init__()
self.score = score
2015-04-25
已采纳回答 / 慕斯卡0428540
不对, f=int(math.sqrt(x)) 是一个赋值语句,把int(math.sqrt(x)) 的值赋给f,不是一个逻辑判断语句,逻辑判断语句应该用“==”才对
2015-04-24
import time
def performance(f):
def tm(x):
print 'call factorial() in',time.asctime(time.localtime(time.time()))
return f(x)
return tm
@performance
def factorial(n):
return reduce(lambda x,y: x*y, range(1, n+1))
print factorial(10)
求赞
def performance(f):
def tm(x):
print 'call factorial() in',time.asctime(time.localtime(time.time()))
return f(x)
return tm
@performance
def factorial(n):
return reduce(lambda x,y: x*y, range(1, n+1))
print factorial(10)
求赞
2015-04-24
def count():
fs = []
for i in range(1,4):
def f(j):
return lambda :j*j
fs.append(f(i))
return fs
f1, f2, f3 = count()
print f1(), f2(), f3()
求赞
fs = []
for i in range(1,4):
def f(j):
return lambda :j*j
fs.append(f(i))
return fs
f1, f2, f3 = count()
print f1(), f2(), f3()
求赞
2015-04-24
def cmp_ignore_case(s1, s2):
Str1=s1.capitalize()
Str2=s2.capitalize()
if Str1>Str2:
return 1
if Str1<Str2:
return -1
else :
return 0
print sorted(['bob', 'about', 'Zoo', 'Credit'], cmp_ignore_case)
Str1=s1.capitalize()
Str2=s2.capitalize()
if Str1>Str2:
return 1
if Str1<Str2:
return -1
else :
return 0
print sorted(['bob', 'about', 'Zoo', 'Credit'], cmp_ignore_case)
2015-04-24
def calc_prod(lst):
def xx():
return reduce(lambda x,y:x*y,lst)
return xx
f = calc_prod([1, 2, 3, 4])
print f()
def xx():
return reduce(lambda x,y:x*y,lst)
return xx
f = calc_prod([1, 2, 3, 4])
print f()
2015-04-23