与python d中的format()混淆

2024-10-03 06:28:13 发布

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

我不确定python文档:

format(value[, format_spec])

A call to format(value, format_spec) is translated to
type(value).__format__(format_spec) which bypasses the
instance dictionary when searching for the value’s 
__format__() method.

是打字错误吗?我认为应该翻译成:

type(value).__format__(value, format_spec)

Tags: thetoinstance文档formatwhichdictionaryis
2条回答

是的,^{} special method的文档有签名:

object.__format__(self, format_spec)

是的,你说得对。以下代码。。。你知道吗

format(foo, "bar")

调用。。。你知道吗

type(foo).format(foo, "bar")

相关问题 更多 >