python-静态属性,,@property的


@property的作用是:直接运行被装饰的函数,不能带参数,表面上看就是在被装饰的函数后面直接加括号。

class Room:    tag=1    def __init__(self,name,owner,width,length,heigh):        self.name=name        self.owner=owner        self.width=width        self.length=length        self.heigh=heigh    @property    def cal_area(self):        # print(‘%s 住的 %s 总面积是%s‘ % (self.owner,self.name, self.width * self.length))        return  self.width * self.length    @classmethod    def tell_info(cls,x):        print(cls)        print(‘--》‘,cls.tag,x)#print(‘--》‘,Room.tag)    # def tell_info(self):    #     print(‘---->‘,self.tag)    @staticmethod    def wash_body(a,b,c):        print(‘%s %s %s正在洗澡‘ %(a,b,c))    def test(x,y):        print(x,y)# Room.wash_body(‘张三‘,‘李四‘,‘王五‘)print(Room.__dict__)r1=Room(‘卧室‘,‘张三‘,100,100,100000)print(r1.__dict__)# r1.wash_body(‘张三‘,‘李四‘,‘王五‘)# Room.test(1,2)# r1.test(1,2)

python-静态属性

评论关闭