callable(object):
這個函數的作用是檢查一個對象是否可以調用的。如果返回True,object仍然可能調用失敗。但是返回False,則調用object一定不會成功。
需要注意的是:類是可以調用的,類的調用返回這個類的一個實例。而類的實例需要定義了__call__()纔可以調用。
例子:
class example:
def __call__(self):
print 'called'
test = example() #produce an instance of a class
test() #the output is called
callable(example) #the output is True
callable(test) #the output is True, if not define __call__ function, the output is False