8.Python3类属性
2019-05-31 本文已影响0人
一枼落知天下
class Room:
country = "中国"
city = "成都"
def __init__(self,name,owner):
self.name = name
self.owner = owner
# 静态属性
@property
def detail(self):
print("%s的主人:%s"%(self.name,self.owner))
# 类方法,跟实例没有绑定关系,跟类绑定
@classmethod
def address(cls):
print("%s玉林北路1号"%cls.city)
# 静态方法,跟实例和类都没有绑定关系
# 名义上归类管理,不能使用类属性和实例属性,
# 只是类的工具包
# 存在于类的属性或字典中
# Room.__dict__
@staticmethod
def bathRoom():
print("正在洗澡...")
if __name__ == '__main__':
print(Room.__dict__)
r1 = Room("帅府豪宅","JhouShuai")
print(r1.__dict__)
# r1.detail
# Room.address()