What is a “callable”?

前端 未结 12 2103
谎友^
谎友^ 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条回答
  •  闹比i
    闹比i (楼主)
    2020-11-22 02:09

    Callable is a type or class of "Build-in function or Method" with a method call

    >>> type(callable)
    
    >>>
    

    Example: print is a callable object. With a build-in function __call__ When you invoke the print function, Python creates an object of type print and invokes its method __call__ passing the parameters if any.

    >>> type(print)
    
    >>> print.__call__(10)
    10
    >>> print(10)
    10
    >>>
    

    Thank you. Regards, Maris

提交回复
热议问题