Python function-Callable (object)

Source: Internet
Author: User
Callable (object)

英文说明: Check whether object is callable. If return true,object still may fail, but if return false, calling object Ojbect will never succeed.

Note: The class is callable, and an instance of the class implements the __call__ () method to invoke.

Version: This function is available in the python2.x version. However, it was removed in the python3.0 version and was re-added in the later version of python3.2.


English Description: Return True If the object argument appears callable, False if not. If this returns true, it's still possible that a call fails, and if it is false, calling object would never succeed. Note that classes is callable (calling a class returns a new instance); Class instances is callable if they has a __call__ () method.


code example:

>>> Callable (0) false>>> callable ("MyString") false>>> def add (A, B): ...     Return a + b...>>> callable (add) True>>> Class A:      ... Def method (self): ...         Return 0...>>> callable (a) true>>> a = A () >>> callable (a) false>>> class B: ...     def __call__ (self): ...         return 0...>>> callable (b) true>>> B = B () >>> callable (b) True
  • 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.