__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
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
class Student(Person):
def __init__(self, name, gender, score):
super(Student, self).__init__(name, gender)
self.score = score
def __str__(self):
return '(Student: %s, %s, %s)'%(self.name,self.gender,self.score)
__repr__=__str__
def __init__(self, name, gender, score):
super(Student, self).__init__(name, gender)
self.score = score
def __str__(self):
return '(Student: %s, %s, %s)'%(self.name,self.gender,self.score)
__repr__=__str__
2015-04-23
在json/decoder.py中提示“No JSON object could be decoded”,所以在read()方法中要返回具有json格式的原始字符串,最简单的就是[]
2015-04-23
def calc_prod(lst):
def multi(a,b):
return a*b
def reduceX():
return reduce(multi,lst)
return reduceX
f = calc_prod([1, 2, 3, 4])
print f()
def multi(a,b):
return a*b
def reduceX():
return reduce(multi,lst)
return reduceX
f = calc_prod([1, 2, 3, 4])
print f()
2015-04-22