0
Can anybody give a simple example of ValueError?
2 ответов
+ 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().
https://www.google.com/amp/s/www.geeksforgeeks.org/factorial-in-JUMP_LINK__&&__python__&&__JUMP_LINK/amp/
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.