在Python 2.7.5中,我尝试了以下方法:
class compl1:
def __mul__(A,B):
adb=56
return adb
def __truediv__(A,B):
adb=56
return adb
u=compl1()
z=compl1()
print u*z
print u/z
Run Code Online (Sandbox Code Playgroud)
为什么只有u*z工作,而u/z给出:
TypeError: unsupported operand type(s) for /: 'instance' and 'instance'
Run Code Online (Sandbox Code Playgroud)