the difference __str__ and __repr__
Posted dragonbird
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了the difference __str__ and __repr__相关的知识,希望对你有一定的参考价值。
First, let me reiterate the main points in Alex’s post:
- The default implementation is useless (it’s hard to think of one which wouldn’t be, but yeah)
__repr__
goal is to be unambiguous__str__
goal is to be readable- Container’s
__str__
uses contained objects’__repr__
>>> class Foo(object): def __repr__(self): return ‘repr‘ >>> f1=Foo() >>> f1 repr >>> print(f1) repr >>> str(f1) ‘repr‘ >>> repr(f1) ‘repr‘ >>> class Foo2(object): def __str__(self): return ‘repr‘ >>> f2=Foo2() >>> f2 <__main__.Foo2 object at 0x0000000002FF3F98> >>> print(f2) repr >>> str(f2) ‘repr‘ >>> repr(f2) ‘<__main__.Foo2 object at 0x0000000002FF3F98>‘
https://stackoverflow.com/questions/1436703/difference-between-str-and-repr-in-python
以上是关于the difference __str__ and __repr__的主要内容,如果未能解决你的问题,请参考以下文章
pay for ; the difference ; their improve without write stop parents instead of a way seldom respect
LeetCode:Find the Difference_389
LeetCode_389. Find the Difference
The difference between "#" and "$" in MyBatis _mybatis
sbt assembly编译打包时报: deduplicate: different file contents found in the following: