类的动态创建方式
# 类的动态创建方式
def run(self):
print("self打印结果 ,", self)
@classmethod
def eat(cls):
print("cls打印结果 , ", 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()
#运行结果
18
180
self打印结果 ,<__main__.Person object at 0x000001593E263F48>
cls打印结果 , <class '__main__.Person'>
staticmethod