Can anybody give a simple example of ValueError? | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite

Can anybody give a simple example of ValueError?

9th Jul 2018, 7:14 AM
1 Réponse
+ 3
From the Py docs: "... Raised when a built-in operation or function receives an argument that has the right type but an inappropriate value, and the situation is not described by a more precise exception such as IndexError... " As I understand it, an instance of ValueError would be, to pass a negative integer to a function which accepts integers, but requires positive integers to work properly, e.g. math.factorial(). math.factorial(x) Parameters : x : The number whose factorial has to be computed. Return value : Returns the factorial of desired number. Exceptions : Raises Value error if number is negative or non-integral.
9th Jul 2018, 7:44 AM
Hatsy Rei
Hatsy Rei - avatar