Chapters
Python114 chapters

ReferenceException types

TypeError

The wrong type altogether, or the wrong number of arguments.

Signature

TypeError(message)

Returns

Raised by operations that do not apply to that type.

Example

Python
try:
    "Age: " + 36
except TypeError:
    print("cannot add a number to a string")

try:
    len(5)
except TypeError:
    print("an int has no length")

Output

cannot add a number to a string
an int has no length

See also