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