我正在尝试更改 python 的 int 类的行为,但我不确定是否可以使用纯 python 来完成。到目前为止,这是我尝试过的:
import builtins
class int_new(builtins.int):
def __eq__(self, other):
return True
int = int_new
print(5 == 6) # the result is False, but I'm anticipating True
请您参考如下方法:
您应该将最后一行替换为:
print(int(5) == int(6))
强制/要求 Python 使用您的新类来处理整数。
