必须返回字符串
class PoloBlog: def __init__(self, name): self.name = name blog1 = PoloBlog("小菠萝") print(blog1) # 输出结果 <__main__.PoloBlog object at 0x1078a4dc0>
class PoloBlog: def __init__(self, name): self.name = name def __str__(self): return "name is %s" % self.name blog1 = PoloBlog("小菠萝") print(blog1) # 输出结果 name is 小菠萝