def f1(x, y):
return x * y
def calc_prod(lst):
def lazy_prod():
return reduce(f1,lst)
return lazy_prod
f = calc_prod([1, 2, 3, 4])
print f()
return x * y
def calc_prod(lst):
def lazy_prod():
return reduce(f1,lst)
return lazy_prod
f = calc_prod([1, 2, 3, 4])
print f()
2016-07-19
cmp和key:http://blog.csdn.net/harry_haiwei/article/details/49616409
2016-07-19
class Person():
pass
xiaoming = Person()
xiaohong = Person()
print xiaoming
print xiaohong
print xiaoming == xiaohong
不加object
pass
xiaoming = Person()
xiaohong = Person()
print xiaoming
print xiaohong
print xiaoming == xiaohong
不加object
2016-07-19
import __future__
s = 'am I an unicode?'
print isinstance(s, unicode)
这样就不对?
s = 'am I an unicode?'
print isinstance(s, unicode)
这样就不对?
2016-07-19
def performance(unit):
def performance_dec(f):
def fn(*args, **kw):
t1 = time.clock()
res = f(*args, **kw)
print 'call %s() in %f %s' % (f.__name__, (time.clock() - t1)*1000, unit)
return res
return fn
return performance_dec
def performance_dec(f):
def fn(*args, **kw):
t1 = time.clock()
res = f(*args, **kw)
print 'call %s() in %f %s' % (f.__name__, (time.clock() - t1)*1000, unit)
return res
return fn
return performance_dec
2016-07-19
class Person(object):
def __init__(self, name, score):
self.name = name
self.__score = score
p = Person('Bob', 59)
try:
print p.name
print p.__score
except AttributeError:
print 'attributeerror'
def __init__(self, name, score):
self.name = name
self.__score = score
p = Person('Bob', 59)
try:
print p.name
print p.__score
except AttributeError:
print 'attributeerror'
2016-07-19
class Person(object):
pass
p1 = Person()
p1.name = 'Bart'
p2 = Person()
p2.name = 'Adam'
p3 = Person()
p3.name = 'Lisa'
L1 = [p1, p2, p3]
L2 = [p2,p1,p3]
print L2[0].name
print L2[1].name
print L2[2].name
pass
p1 = Person()
p1.name = 'Bart'
p2 = Person()
p2.name = 'Adam'
p3 = Person()
p3.name = 'Lisa'
L1 = [p1, p2, p3]
L2 = [p2,p1,p3]
print L2[0].name
print L2[1].name
print L2[2].name
2016-07-19
应该是说,在外部是可以修改__count属性的,但是不能访问,所以在Class外面打Print Person.__count会报错,但是如果在里面写一个打印的命令的话会看到__count是有加一的
2016-07-18