当操作或函数应用于不适当类型的对象时引发。关联值是一个字符串,提供有关类型不匹配的详细信息。
用户代码可能会引发此异常,以指示不支持(并且无意支持)对对象进行的尝试操作。如果一个对象旨在支持给定的操作但尚未提供实现,则 NotImplementedError 是引发的正确异常。
传递错误类型的参数(例如,在需要 int 时传递列表)应导致 TypeError,但传递错误值的参数(例如超出预期边界的数字)应导致 ValueError。
Google Translate · 此内容为自动翻译。技术术语及适用条件请以英文原文为准。
官方说明 · 原文
Raised when an operation or function is applied to an object of inappropriate type. The associated value is a string giving details about the type mismatch.
This exception may be raised by user code to indicate that an attempted operation on an object is not supported, and is not meant to be. If an object is meant to support a given operation but has not yet provided an implementation, NotImplementedError is the proper exception to raise.
Passing arguments of the wrong type (e.g. passing a list when an int is expected) should result in a TypeError, but passing arguments with the wrong value (e.g. a number outside expected boundaries) should result in a ValueError.
修改记录:English prose extracted; whitespace normalized; Korean context and classified official links added. Python code examples not redistributed. 译文说明已标注为自动翻译。