+ 3
What is the difference between ValueError and TypeError exceptions?
2 Antworten
+ 4
value error is when data type entered is correct but in appropriate value like u have made a function which returns the square root of a number
so passing a negative number as an
argument will give value error
and type error is explained
+ 4
>>> '2' + 2 Traceback (most recent call last): File "<stdin>", line 1, in ?
TypeError: Can't convert 'int' object to str implicitly
this is an example for type error
def contains(string,char):
list = []
for i in range(0,len(string)):
if string[i] == char:
list = list + [i] return list[-1]
contains('bababa', 'k')
ValueError: could not find k in bababa