静态方法:@staticmethod
不能访问实例属性!!! 参数不能传入self!!!
与类相关但是不依赖类与实例的方法!!
staticmethod静态方法只是名义上的归属类管理,不能使用类变量和实例变量,是类的工具包
class Room:
tag=1
def __init__(self,name,owner,width,lenggth,heigh):
self.name=name
self.owner=owner
self.width=width
self.lenggth=lenggth
self.heigh=heigh
@property #是class提供的 主要是把后面的逻辑影藏起来
def cal_area(self):
#print("%s 住的 %s 总面积是 %s" %(self.owner,self.name,self.width*self.heigh))
return self.width*self.heigh
def test(self):
print("form test",self.name)
@classmethod #类 是给类用的跟实例没关系
def tell_info(cls):
print(cls)
print(">>>",cls.tag)
# def tell_info(self):
# print(">>>>",self.tag)
@staticmethod #类的工具包
def wash_body(a,b,c):
print("%s %s %s 正在洗澡"%(a,b,c))
Room.wash_body(1,2,3)
r1=Room("测随","alex",11,33,4)
r1.wash_body(1,2,3)