python关于类型转换的问题
本帖最后由 tina437213 于 2013-03-24 17:58:21 编辑
class circle(object):
def __init__(self,radius):
self.radius=radius
def getarea(self):
return self.radius*self.radius*math.pi
def setarea(self,value):
self.radius=math.sqrt((value/math.pi))
Area = property(getarea,setarea,doc = "area of the circle")
import math
c=circle(3)
print c.Area.__doc__
运行结果
float(x) -> floating point number
Convert a string or number to a floating point number, if possible.
?为什么要转换了,我就是想输出字符串呀。。。 python string float
[解决办法]
print circle.Area
<property object at 0x021B81B0>
类也是个对象,自然是可以用.操作符调用其方法或属性,property比较特殊,你用实例操作的话就发生函数调用,所以说才改用类本身来操作...