+ 3

What is the difference between ValueError and TypeError exceptions?

5th Jul 2016, 4:42 PM
Protiti sengupta
Protiti sengupta - avatar
2 Respuestas
+ 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
6th Jul 2016, 5:53 PM
Vansh Batra
Vansh Batra - avatar
+ 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
20th Aug 2016, 5:30 PM
Biswajit Samal
Biswajit Samal - avatar