try:
print p.__score
except AttributeError:
print ("AttributeError")
print p.__score
except AttributeError:
print ("AttributeError")
2019-08-20
from __future__ import unicode_literals
s = 'am I an unicode?'
print isinstance(s, unicode)
s = 'am I an unicode?'
print isinstance(s, unicode)
2019-08-20
import functools
sorted_ignore_case = functools.partial(sorted,key=lambda a:a.upper())
print sorted_ignore_case(['bob', 'about', 'Zoo', 'Credit'])
sorted_ignore_case = functools.partial(sorted,key=lambda a:a.upper())
print sorted_ignore_case(['bob', 'about', 'Zoo', 'Credit'])
2019-08-20
def performance(unit):
def pre(f):
def fn(*args,**kw):
t1=time.time()
def pre(f):
def fn(*args,**kw):
t1=time.time()
2019-08-19
import time
def performance(f):
def logtime(*args, **kw):
t1=time.time()
r=f(*args, **kw)
t2=time.time()
print 'call'+f.__name__ +'()in'+ str(t2-t1)
return f(*args, **kw)
return logtime
@performance
def factorial(n):
return reduce(lambda x,y: x..
def performance(f):
def logtime(*args, **kw):
t1=time.time()
r=f(*args, **kw)
t2=time.time()
print 'call'+f.__name__ +'()in'+ str(t2-t1)
return f(*args, **kw)
return logtime
@performance
def factorial(n):
return reduce(lambda x,y: x..
2019-08-19
https://blog.csdn.net/xiangxianghehe/article/details/77170585###;http://python.jobbole.com/82344/
看完这个感觉不难了呀。看不懂硬着头皮看三天也不去别处找帖子的同学,我真是服
看完这个感觉不难了呀。看不懂硬着头皮看三天也不去别处找帖子的同学,我真是服
2019-08-19
如果不用@,可以这么写:
import time
def performance(f):
def fn(x):
print 'call factorial() in',time.time()
return f(x)
return fn
def factorial(n):
r=reduce(lambda x,y: x*y, range(1, n+1))
print r
return r
performance(factorial)(10)
import time
def performance(f):
def fn(x):
print 'call factorial() in',time.time()
return f(x)
return fn
def factorial(n):
r=reduce(lambda x,y: x*y, range(1, n+1))
print r
return r
performance(factorial)(10)
2019-08-19
其实没那么难理解,这段课讲得不好
我参考的这里:
https://blog.csdn.net/u012759262/article/details/79749299
我参考的这里:
https://blog.csdn.net/u012759262/article/details/79749299
2019-08-19
# 希望一次返回3个函数,分别计算1x1,2x2,3x3:
def count():
fs = []
for i in range(1, 4):
def f():
return i*i
fs.append(fs) #教程里这里和return后面的写反了
return f
f1, f2, f3 = count()
def count():
fs = []
for i in range(1, 4):
def f():
return i*i
fs.append(fs) #教程里这里和return后面的写反了
return f
f1, f2, f3 = count()
2019-08-18
return liancheng()
加不加括号差别好大啊,不加括号返回的是函数,加括号就成了返回结果值。正确的应是不加括号
加不加括号差别好大啊,不加括号返回的是函数,加括号就成了返回结果值。正确的应是不加括号
2019-08-16
def count():
fs = []
for i in range(1, 4):
def f(i):
return lambda:i*i
fs.append(f(i))
return fs
fs = []
for i in range(1, 4):
def f(i):
return lambda:i*i
fs.append(f(i))
return fs
2019-08-16
def format_name(s):
return s[0:1].upper()+s[1:].lower()
print map(format_name, ['adam', 'LISA', 'barT'])
return s[0:1].upper()+s[1:].lower()
print map(format_name, ['adam', 'LISA', 'barT'])
2019-08-15
import math
def add(x, y, f):
return f(x) + f(y)
print add(25, 9, math.sqrt)
def add(x, y, f):
return f(x) + f(y)
print add(25, 9, math.sqrt)
2019-08-15