Base de conhecimentoCentro de Exames
PT · PTPortuguês (Portugal)
Escolher idioma13

CKTIS / Python

callable()

Verifica se o objeto pode ser chamado, por exemplo uma função, uma classe ou uma instância cujo tipo define `__call__`.

Versão: Python 3.14; repository image, production runtime not attested

Sintaxe

callable(object, /)

Verifica se o objeto pode ser chamado, por exemplo uma função, uma classe ou uma instância cujo tipo define __call__.

len dá True e o inteiro 4 dá False. A lista de argumentos não é verificada.

Chamar len sem o objeto exigido continua a gerar TypeError.

class Scale:
    def __call__(self, x): return 2*x
f = Scale()
assert callable(Scale) and callable(f) and f(3) == 6 and not callable(4)

Exemplos

print(callable(len), callable(4))
try:
    len()
except TypeError as error:
    print(type(error).__name__)

Resultado

True False
TypeError

Chamar len sem o objeto exigido continua a gerar TypeError.

Fontes