NotImplemented
NotImplemented
它是什么?
NotImplemented 是Python在内置命名空间中的六个常数之一。
其他有False、True、None、Ellipsis 和 debug。
和 Ellipsis很像,[NotImplemented] 能被重新赋值(覆盖)。
对它赋值,甚至改变属性名称, 不会产生 SyntaxError。所以它不是一个真正的“真”常数。当然,我们应该永远不改变它。 但是为了完整性:
>>> None = 'hello'
...
SyntaxError: can't assign to keyword
>>> NotImplemented
NotImplemented
>>> NotImplemented = 'do not'
>>> NotImplemented
'do not'
它有什么用?什么时候用?
NotImplemented 是个特殊值,
它能被二元特殊方法返回:
__eq__()、 lt() 、 add() 、 rsub() 等)
>>> bool(NotImplemented)
True