- >>> class test():
- def __init__(self):
- pass
- def __repr__(self):
- return 1sdf
- >>> t = test()
- >>> t #不用 print 直接打印出重构的值, 面向程序, 在程序中传递
- 1sdf
- >>> class test(Exception):
- def __init__(self):
- pass
- def __str__(self): #p
- return 1sdf
- >>> print(test()) #调用 print 打印重构值, 面向用户交互, 首先调用__str__的值
- 1sdf
- >>> test() #打印输出为函数
来源: http://www.bubuko.com/infodetail-2510335.html