我想为int
重新定义__add__
方法,这样用法如下:
>> 1+2
=> "1 plus 2"
>> (1).__add__(2)
=> "1 plus 2"
我试过了:
^{2}$但是,它引发了一个例外:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: can't set attributes of built-in/extension type 'int'
有人知道为什么我不能像这样重新定义__add__
方法吗?还有别的办法吗?在
目前没有回答
相关问题
PyPI热门下载资源包