と は Python の組み込み数値型 ( 、、、および)repr
で同一ですか、それとも 2 つが異なる結果をもたらす可能性がある (難解な?) 状況はありますか?str
int
bool
float
complex
SO に関する関連する質問 ( this one__repr__
など) は、実装方法と__str__
実装方法が異なり、文字列に対して異なる値を返すことに焦点を当てていますが、数値の実際の実装については何も見つかりません。
と は Python の組み込み数値型 ( 、、、および)repr
で同一ですか、それとも 2 つが異なる結果をもたらす可能性がある (難解な?) 状況はありますか?str
int
bool
float
complex
SO に関する関連する質問 ( this one__repr__
など) は、実装方法と__str__
実装方法が異なり、文字列に対して異なる値を返すことに焦点を当てていますが、数値の実際の実装については何も見つかりません。
Your primary source of information on this is http://hg.python.org/cpython/file/tip/Objects
For example, in boolobject.c
:
PyTypeObject PyBool_Type = {
...stuff...
bool_repr, /* tp_repr */
...stuff...
bool_repr, /* tp_str */
so yes, they're guaranteed to be the same.
For floats, float_repr
is different from float_str
and depends on sys.float_repr_style
.