What is a “callable”?

前端 未结 12 2394
谎友^
谎友^ 2020-11-22 01:23

Now that it\'s clear what a metaclass is, there is an associated concept that I use all the time without knowing what it really means.

I suppose everybody made once

12条回答
  •  半阙折子戏
    2020-11-22 02:22

    To check function or method of class is callable or not that means we can call that function.

    Class A:
        def __init__(self,val):
            self.val = val
        def bar(self):
            print "bar"
    
    obj = A()      
    callable(obj.bar)
    True
    callable(obj.__init___)
    False
    def foo(): return "s"
    callable(foo)
    True
    callable(foo())
    False
    

提交回复
热议问题