Python callable()

The callable() method checks if a object is callable. Callable objects are True if object is callable and False if object is not callable.

Syntax & Parameters

callable(object)

 The callable() method takes one argument, an object and returns one of the two values:

  • returns True, if the object appears to be callable.
  • returns False, if the object is not callable.

Example

def callIt(): 
    return 1 
  
# CReating object 
ex = callIt 
print(callable(ex))

#Not Callable 
x= 1
print(callable(x))

Output

True
False 
class Foo:
  def __call__(self):
    print(callable(ex))

ex = Foo()
ex() #calling callable 

Output

True

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s