摘要: 1.Python类数据属性:定义在类里面但在函数外面的变量,它们都是静态的。 #一段很简单的代码,但反应了很多 >>> class A(): a=1 #一个类里面有个属性a >>> a=A() >>> b=A() >>> a.a 1 >>> b.a 1 >>> A.a 1 #这个属性能被实例和类访问 阅读全文
posted @ 2016-02-18 21:07 dreamfor 阅读(9483) 评论(0) 推荐(0) 编辑
摘要: 偏函数 一个带n 个参数,curried 的函数固化第一个参数为固定参数,并返回另一个带n-1 个参数函数对象 >>> from functools import partial >>> convert=partial(int,base=2) >>> convert('11111111') 255 阅读全文
posted @ 2016-02-18 16:03 dreamfor 阅读(285) 评论(0) 推荐(0) 编辑
摘要: filter用法 filter(func,seq) 将seq的元素逐一代入func,通过func的返回值来判断是保留还是过滤 1 >>> def foo(x): 2 return x>3 3 4 >>> filter(foo,range(6)) 5 [4, 5] >>> filter(lambda 阅读全文
posted @ 2016-02-18 10:58 dreamfor 阅读(425) 评论(0) 推荐(0) 编辑