int.\uu格式的python格式规范__

2024-04-26 13:55:28 发布

您现在位置:Python中文网/ 问答频道 /正文

我有理由直接给int.__format__打电话。我试了以下方法

>>> object.__format__(1,'d')

但有个例外

TypeError: unsupported format string passed to int.__format__

fmt_spec应该是什么?你知道吗


Tags: to方法formatstringobjectintspec理由
1条回答
网友
1楼 · 发布于 2024-04-26 13:55:28

object.__format__称为object.__format__,而不是int.__format__。你知道吗

请尝试以下操作:

>>> (1).__format__('d')
'1'

传递给object.__format__的非空字符串的行为是documented

Changed in version 3.4: The __format__ method of object itself raises a TypeError if passed any non-empty string.

相关问题 更多 >