Built-in Exceptions

TypeError — exception class

An operation receives an unsuitable object type or is unsupported for the supplied operands. A correct type with an invalid value more often produces ValueError. Check the call contract rather than blindly coercing every argument. Catch TypeError when this category is the recovery boundary; do not rely on the exact human-readable message.

Formal Syntax & Structure

python syntaxpython
TypeError

Return Value

type

The class object TypeError; this reference documents the class identity, not a universal constructor signature.

Working Example

Example Snippetpython
try:    len(42)except TypeError as error:    print(type(error).__name__)
Python Reference