The example above:
\n", "def square(x):\n", " if isinstance(x, str):\n", " raise ValueError("x can not be a string")\n", " else:\n", " return x**2\n", "
uses ValueError
, what type of error would be more appropriate?
TypeError
should be raised when the type (i.e. str
, float
, int
) is incorrect.