The _ call _ about Python has such an explanation in the official documentation (http://docs.python.org/reference/datamodel.html? Highlight =__ call __# object. _ call __)
Object._ Call __(Self[,ARGs...])
Called when the instance is "called" as a function; if this method is defined,X (arg1, Arg2, ...)Is a shorthandX._ Call __(Arg1, Arg2, ...).
When an instance is called as a method, such as instance (arg1, args2 ,...), in fact, the instance is called. _ call _ (arg1, arg2 ,...)
First, let's look at the following:
In [5]: Class :...: def _ init _ (Self ):...: Print "_ init _ method "...: def _ call _ (Self ):...: Print "_ call _ method "...: In [6]: A = a () _ init _ methodin [7]: A () _ call _ Method
The following can be ignored ......
# Coding: UTF-8 "" demo for _ call _ http://docs.python.org/reference/datamodel.html? Highlight =__ call __# object. _ call _ when we use an instance of a class as a method, the _ call _ method "Class: def _ init _ (self, ARG): Print "init" self. arg = Arg def _ call _ (Self): Print "A" Print self. arg if _ name _ = "_ main _": c = a ("AAAAA") C () # at this time, C is just an instance ), we generally use C. methodname (), but now () is directly added after the instance, which is called as a method. At this time, C (arg1, arg2,...) will be called ,....) it is equivalent to C. _ call _ (self, arg1, arg2 ,...)