CKTIS / Python
callable()
Overí, či možno objekt volať, napríklad funkciu, triedu alebo inštanciu, ktorej typ definuje `__call__`.
Verzia: Python 3.14; repository image, production runtime not attested
Syntax
callable(object, /)Overí, či možno objekt volať, napríklad funkciu, triedu alebo inštanciu, ktorej typ definuje __call__.
Pre len vráti True a pre celé číslo 4 False. Zoznam argumentov nekontroluje.
Volanie len bez požadovaného objektu stále vyvolá 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)
Príklady
print(callable(len), callable(4))
try:
len()
except TypeError as error:
print(type(error).__name__)
Výsledok
True False TypeError
Volanie len bez požadovaného objektu stále vyvolá TypeError.