<
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 中国标准时间

被折叠的 条评论
为什么被折叠?



