Python function-callable (object)

Source: Internet
Author: User
Python function-callable (object)

Description: checks whether the object is callable. If True is returned, the object may still fail to be called. if False is returned, the object called ojbect will never succeed.

Note: The class is callable, and the class instance can only call the _ call _ () method.

Version: This function is available in python2.x. However, it is removed from Python and added in versions later than Python.


Return True if the object argument appears callable, False if not. if this returns true, it is still possible that a call fails, but if it is false, calling object will never succeed. note that classes are callable (calling a class returns a new instance); class instances are callable if they have 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.