【发布时间】:2010-11-24 18:36:21
【问题描述】:
我不知道这是否是 3.1 中的错误,但如果我没记错的话,“内联”除法在 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
但是,3.1 给了我这个:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for /=: 'A' and 'int'
...还是我错过了什么?
【问题讨论】:
标签: python python-3.x