The callable of Python

Source: Internet
Author: User

Callback is a python built-in function

English Description:

Callable (object)

Return True If the object argument appears callable,false if not. If this return true,it was still posssible that a call fails,but if it is false, calling object would never succeed. Note that classes is callable (calling a class returns a new Instence); Instance is callable if Theri class has a __call__ () method

Description

The 1 method is used to detect whether an object can be called, and can be called by means of whether the object can be called using () parentheses.

2 callable object may fail in actual invocation, but cannot invoke object, the invocation must not succeed

3 class objects are callable objects, whether an instance object of the class can be called, depending on whether the class defines the __call__ method

>>> class A: #定义类A    pass>>> Callable (a) #类A是可调用对象True >>> a = A () #调用类A >>> Callable (a) #实例a不可调用False >>> a () #调用实例a失败Traceback (most recent):  File "<pyshell#31>", Line 1, in <module>    A () TypeError: ' A ' object was not callable>>> class B: #定义类B    def __call__ (self): C4/>print (' instances is callable now. ')        >>> callable (b) #类B是可调用对象True >>> B = B () #调用类B >>> callable (b) #实例b是可调用对象True >>> B () #调用实例b成功instances is callable now.

  

Reprint: https://www.cnblogs.com/sesshoumaru/p/5983979.html

The callable of Python

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.