我知道partial
函数于functools
,但是在一般的 python 程序(不是:Haskell、Erlang、Clojure 等)中编写函数来返回 Python 中的函数有多常见?
例如:
>>> def returnfunk(xs):
... return lambda x: list(filter(lambda y: x == y, xs))
...
>>> fn = returnfunk(["cat", "dog", "horse"])
>>>
>>> (fn("cow") == []) == True
True
>>> (fn("cat") == ['cat']) == True
True
>>>
>>> list(filter(fn, ["zebra", "elephant", "dog", "parrot", "cat"]))
['dog', 'cat']
是为了real (python) world
还是更多的爱好、学术、兴趣?
装饰者@classmethod
and @staticmethod
这是两个例子。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)