類的動(dòng)態(tài)創(chuàng)建方式
# 類的動(dòng)態(tài)創(chuàng)建方式
def run(self):
print("self打印結(jié)果 ,", self)
@classmethod
def eat(cls):
print("cls打印結(jié)果 , ", cls)
@staticmethod
def sleep():
print("staticmethod")
person = type("Person", (), {"age": 18, "height": 180, "run": run, "eat": eat, "sleep": sleep})
p = person()
print(p.age)
print(p.height)
p.run()
p.eat()
p.sleep()
#運(yùn)行結(jié)果
18
180
self打印結(jié)果 ,<__main__.Person object at 0x000001593E263F48>
cls打印結(jié)果 , <class '__main__.Person'>
staticmethod