Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Python callable() Function

Python callable() Function

Python built-in function Python built-in function


Description

callable() The function is used to check whether an object is callable. If True is returned, the object may still fail to be called; but if False is returned, calling the object will definitely not succeed.

For functions, methods, lambda functions, classes, and class instances that implement the call method, it returns True.

Syntax

callable() Method Syntax:


callable(object)

Parameters

Return Value

Returns True if callable, otherwise returns False.

Example

The following examples show the use of callable():

callable

(

0

)

False

callable

(

"

runoob

"

)

False

def

add

(

a

,

b

)

: ...

return

a

b

... >>>

callable

(

add

)

The function returns True

True

class

A

:

class

...

def

method

(

self

)

: ...

return

0

... >>>

callable

(

A

)

The class returns True

True

a

=

A

(

)

callable

(

a

)

Does not implement call, returns False

False

class

B

: ...

def

call

(

self

)

: ...

return

0

... >>>

callable

(

B

)

True

b

=

B

(

)

callable

(

b

)

Create a class that implements call, returns True

True

Python built-in function Python built-in function