V2EX  ›  英汉词典

ValueError

释义 Definition

ValueError:常见于 Python 等编程语境的异常名,表示“值错误”——传入的参数类型可能是对的,但其取值不合法/不在允许范围内,因此无法完成操作。(在 Python 中属于内置异常类型之一。)

发音 Pronunciation (IPA)

/ˈvæljuː ˌɛrər/

例句 Examples

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,所以我们会在处理前先校验输入。

词源 Etymology

value(数值/取值)+ error(错误) 组成,字面意思是“取值错误”。作为术语主要流行于 Python 的异常命名体系:强调错误原因在于“值不符合要求”,而不一定是数据类型本身不对。

相关词 Related Words

文学与作品中的用例 Literary Works

  • Python Documentation(官方文档,内置异常章节频繁出现 ValueError
  • Automate the Boring Stuff with Python(Al Sweigart)
  • Python Crash Course(Eric Matthes)
  • Fluent Python(Luciano Ramalho)
关于   ·   帮助文档   ·   自助推广系统   ·   博客   ·   API   ·   FAQ   ·   Solana   ·   4445 人在线   最高记录 6679   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 18ms · UTC 05:33 · PVG 13:33 · LAX 22:33 · JFK 01:33
♥ Do have faith in what you're doing.