两者关系
__str__方法其实调用了__repe__方法
__str__为了给使用者准备的;
__repr__为了给开发者准备的。一般要表示出一个对象来源的类和继承关系,了解该对象。
使用方法
class A:
def __str__(self):
def __repr__(self):
print(str(A()))
print(repr(A()))
两者关系
__str__方法其实调用了__repe__方法
__str__为了给使用者准备的;
__repr__为了给开发者准备的。一般要表示出一个对象来源的类和继承关系,了解该对象。
使用方法
class A:
def __str__(self):
def __repr__(self):
print(str(A()))
print(repr(A()))