Python __call__()方法(详解版

原文:http://c.biancheng.net/view/2380.html
本节再介绍 Python 类中一个非常特殊的实例方法,即 call()。该方法的功能类似于在类中重载 () 运算符,使得类实例对象可以像调用普通函数那样,以“对象名()”的形式使用。
举个例子:

class CLanguage:
    # 定义__call__方法
    def __call__(self,name,add):
        print("调用__call__()方法",name,add)

猜你喜欢

转载自blog.csdn.net/qq_45583898/article/details/126582426