当前位置 : 主页 > 编程语言 > python >

python __slot__

来源:互联网 收集:自由互联 发布时间:2022-06-28
class Player(object): def __init__(self,name,age,life): self.name=name self.age=age self.life=life class Player1(object): __slots__=("name","age","life") def __init__(self,name,age,life): self.name=name self.age=age self.life=life p1=Player
class Player(object):
def __init__(self,name,age,life):
self.name=name
self.age=age
self.life=life
class Player1(object):
__slots__=("name","age","life")
def __init__(self,name,age,life):
self.name=name
self.age=age
self.life=life

p1=Player("a",12,33)
p1.aa="2334"
p2=Player1("b",12,33)
p2.bb=21323## 报错
print(dir(p2))

print(set(dir(p1))-set(dir(p2)))

  


上一篇:django dispatch
下一篇:没有了
网友评论