这是因为Python3中,str的输出是调用类的实例方法__str__来输出,如果__str__方法没有重写,则自动继承object类的__str__方法,而object类的__str__方法是调用__repr__方法,因此自定义类未重写__str__方法的情况下,实际上就是调用该类的__repr__方法,因此__repr__方法重写会影响到str的输出,除非在自定义类中也重写__str__方法才可以单独输出信息。

具体可参考:

《Python __repr__方法和__str__方法、内置函数repr和str的异同点对比剖析》

《Python重写自定义类的__repr__方法》

《 Python重写自定义类的__str__方法》

老猿Python,跟老猿学Python! 博客地址:https://blog.csdn.net/LaoYuanPython

最新文章

  1. android开发--Application
  2. linux 设置mysql 数据库编码utf8
  3. EditPlus开发Python的简单设置
  4. 与你相遇好幸运,Sails.js自定义responses
  5. spring文件下载记录
  6. centos搭建NFS网络文件系统
  7. linux包之procps之ps与top
  8. C# 获取图片的EXIF 信息
  9. Android开发之定义接口暴露数据
  10. Spring MVC使用样例
  11. Building Block
  12. 使用lrucache和diskLrucache实现照片墙
  13. Java常用类库 读书笔记 二
  14. Day 4-6 xml处理
  15. bootcdn
  16. hybrid几种模式
  17. Linux笔记(一):CentOS-7安装
  18. POJ 2049— Finding Nemo(三维BFS)10/200
  19. 进阶之路(基础篇) - 011 arduino api基础手册
  20. [BUAA OO]第一次博客作业

热门文章

  1. 【QT】继承QRunnable+QThreadPool实现多线程
  2. python0why study python
  3. 手撸ORM浅谈ORM框架之Query篇
  4. Java8 新特性 —— 函数式编程
  5. shell 之 -f -z -e -o -a -d
  6. linux kernel 的 procfs sysfs 对查问题的帮助
  7. 数据库Sharding的基本思想和切分策略(转)
  8. android打包持续集成
  9. Spring源码之@Lazy和预实例化
  10. (7)ASP.NET Core3.1 Ocelot Swagger