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