标签:for self 对象 span end elf 内容 div bsp
# coding=utf-8 class Publish(): def __init__(self, name): self.name = name def __str__(self): return self.name # def __repr__(self): # return "****" #返回的结果 [****, ****, ****] 会把要显示的对象给覆盖掉 #如果没有 def __repr__ 就会显示[<__main__.Publish object at 0x013E2770>, <__main__.Publish object at 0x013E2750>, <__main__.Publish object at 0x013E2F90>] p = Publish("alex") print("2",p) lis = [] for i in range(3): p = Publish("alex"+str(i)) lis.append(p) print(lis) #[<__main__.Publish object at 0x016F2730>, <__main__.Publish object at 0x016F2750>, <__main__.Publish object at 0x016F2F90>] for i in lis: print(i)#对象 alex0 alex1 alex2 print(i.name)#对象的属性 alex0 alex1 alex2
标签:for self 对象 span end elf 内容 div bsp
原文地址:https://www.cnblogs.com/kenD/p/10072616.html