ValueError:常见于 Python 等编程语境的异常名,表示“值错误”——传入的参数类型可能是对的,但其取值不合法/不在允许范围内,因此无法完成操作。(在 Python 中属于内置异常类型之一。)
/ˈvæljuː ˌɛrər/
I got a ValueError when I tried to convert "abc" to an integer.
我在把“abc”转换成整数时遇到了 ValueError。
If the date string is in the wrong format, the parser will raise a ValueError, so we validate the input before processing.
如果日期字符串格式不正确,解析器就会抛出 ValueError,所以我们会在处理前先校验输入。
由 value(数值/取值)+ error(错误) 组成,字面意思是“取值错误”。作为术语主要流行于 Python 的异常命名体系:强调错误原因在于“值不符合要求”,而不一定是数据类型本身不对。