classfunc
Table of Contents
1 python中class和function的關係
python中的函數也可以這樣實現 原函數的實現如下:
def e2(*args, **kws): return 2 print(e2(1), dir(e2))
通過_call_實現的class,可以使用函數式的調用方式
class E: def __init__(self): print('E.__init__ called') def __call__(self, *args, **kws): print('E.__call__ called') return 2 e = E() print(e(1),dir(e))
從上可以看出函數也可以視爲類的一個對象。
Date: 2013-04-15 16:18:40 中國標準時間