# 创建类 class myClass(object): name="东皇太一"; Age=416466856; shen="真神"; def use(self): print ("这是一个洪荒小说的妖神={}".format(self.name)) item=myClass(); print(item.name) item.name="太素元清"; print(item.name) print(item.use()) class myTest(object): def __init__(self,name="taiyi",Age=0,shen=""): self.name=name; self.Age=Age; self.shen=shen; def use(self): print ("这是一个洪荒小说的妖神={}".format(self.name)) test=myTest(); print (test.name) test1=myTest(name="北京",Age=600,shen="didou"); print (test1.name) #比较2个实体是否相等 class testeq(object): def __init__(self,age): self.age=age; def __eq__(self, other): if self.age==other.age: return True; else: return False; a=testeq(5); b=testeq(6); c=testeq(5); print (a==b); print (a==c);
时间: 2024-10-13 11:53:07