class Vector:
def __init__(self,x=0,y=0,z=0):
self.__x=x;
self.__y=y;
self.__z=z;
self.__length=(self.__x**2+self.__y**2+self.__z**2)**0.5;
......
@property
def length(self):
return self.__length;
Traceback (most recent call last):
File "<pyshell#9>", line 1, in <module>
v.length()
TypeError: 'float' object is not callable
v.length就行
不要v.length()
property这个描述之后就是属性,不是方法。
首先,这不是个特别难解决的问题,问题出现的原因可能有以下3种:
1,因为马虎,导致的语法错误!函数/方法调用时的拼写错误!
2,函数名和变量名一致导致。 如 mean = mean(***)
3,运算符号遗漏。 如a = bc 应改为 a= b*c