p=Person('Bob',59)
Traceback (most recent call last):
File "<pyshell#7>", line 1, in <module>
p=Person('Bob',59)
TypeError: object() takes no parameters
Traceback (most recent call last):
File "<pyshell#7>", line 1, in <module>
p=Person('Bob',59)
TypeError: object() takes no parameters
2016-06-29
def performance(f):
def fn(*args, **kw):
t1 = time.clock()
res = f(*args, **kw)
t2 = time.clock() - t1
print 'call %s() in %f' % (f.__name__, t2)
return res
return fn
def fn(*args, **kw):
t1 = time.clock()
res = f(*args, **kw)
t2 = time.clock() - t1
print 'call %s() in %f' % (f.__name__, t2)
return res
return fn
2016-06-29
import math
def is_sqr(x):
return math.sqrt(x) % 1 == 0
list1 = filter(is_sqr, range(1, 101))
for item in list1:
print(item)
def is_sqr(x):
return math.sqrt(x) % 1 == 0
list1 = filter(is_sqr, range(1, 101))
for item in list1:
print(item)
2016-06-28
from _functools import reduce
def prod(x, y):
return x * y
print(reduce(prod,[2, 4, 5, 7, 12]))
def prod(x, y):
return x * y
print(reduce(prod,[2, 4, 5, 7, 12]))
2016-06-28