property 作用其实把类里面的逻辑给隐藏起来(封装逻辑,让用户调用的时候感知不到你的逻辑)

property实例1:
class
Room:

def __init__(self):
pass

@property #将函数属性变成静态属性(后面调用的时候,就不需要用x.status()来调用了,直接x.status执行即可)
def status(self):
print('123')

R = Room()
R.status #结果打印 123

property实例2:
class Room:
def __init__(self):
pass

@property
def status(self):
return 123

R = Room()
print(R.status) #结果是返回 123


相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-06-10
  • 2022-12-23
  • 2019-03-29
  • 2021-05-14
  • 2022-01-09
猜你喜欢
  • 2022-03-10
  • 2022-12-23
  • 2022-12-23
  • 2021-12-13
  • 2021-06-06
  • 2022-01-04
  • 2021-04-25
相关资源
相似解决方案