89DEVs

Python TypeError Exception

In Python a TypeError Exception is raised when an object of inappropriate type is applied to an operation or function. 

For example if we call the Python built-in function abs() without any argument:

# calling abs() without any argument
abs()

The TypeError exception tells us that "exactly one argument" is required.


Traceback (most recent call last):
  File "", line 1, in 
TypeError: abs() takes exactly one argument (0 given)


If we call the same abs() function with two arguments instead of one argument:

# calling abs() with two instead one argument
abs(1, 2)

exactly the same exception occurs and the exception tell us again, that "exactly one argument" is required.


Traceback (most recent call last):
  File "", line 1, in 
TypeError: abs() takes exactly one argument (2 given)


If we pass arguments with the wrong value instead a ValueError exception is raised.