__str__
class Person(object): def __init__(self,name): self.name=name alex=Person("alex") print(alex) #<__main__.Person object at 0x000001C336D290B8> 此时alex是一个Person实例化的对象 #-----------------------当添加 __str__ 后------------------------------------------------------------ class Person(object): def __init__(self,name): self.name=name def __str__(self): return self.name # alex=Person("alex") print(alex,type(alex)) # alex <class '__main__.Person'> print(alex.__str__) #<bound method Person.__str__ of <__main__.Person object at 0x000001444CCA8160>> print(alex.__str__()) # alex print(str(alex)) # alex