__repr__ 共 1 篇文章

Python __repr__与__str__方法在调试信息中的区别
2026-04-27 13:28:09
Python repr与str方法在调试信息中的区别 在 Python 调试过程中,直接打印自定义对象往往只能看到内存地址(如 <main.Point object at 0x7f...),这对排查问题毫无帮助。为了获得可读的信息,必须重写 str 和 repr 方法。这两者虽然都是将对象转换为字符
Python __str__ __repr__
3 0