我不知道这是否是3.1中的错误,但是如果我没记错,"inline"除法在3k之前的版本中就像这样:
Python 3.1 (r31:73574, Jun 26 2009, 20:21:35) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> class A:
... def __init__(self, x):
... self.x = x
... def __idiv__(self, y):
... self.x /= y
...
>>> a = A(5)
>>> a /= 2
Run Code Online (Sandbox Code Playgroud)
但是,3.1给了我这个:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for /=: 'A' and 'int'
Run Code Online (Sandbox Code Playgroud)
......或者我错过了什么?
Gaaah!发现__floordiv__和__truediv__.抱歉!
如果你想告诉我为什么2to3没有翻译__idiv__成__truediv__a __floordiv__(self, y): self.__truediv__(y),请继续!
| 归档时间: |
|
| 查看次数: |
770 次 |
| 最近记录: |