"jmp" <[email protected]> a écrit dans le message de
news:[email protected]...
On 09/27/2016 04:01 PM, Peng Yu wrote:
Note: function are objects, and can have attributes, however I rarely see usage of these, there
could be good reasons for that.
It could be use to implement a cache for example.
def fact1(n):
if not hasattr(fact1, '_cache'):
fact1._cache = {0:1}
if n not in fact1._cache:
fact1._cache[n] = n * fact1(n-1)
return fact1._cache[n]
--
https://mail.python.org/mailman/listinfo/python-list