2012-10-15 148 views
2

的格式()困惑,我不知道python的文檔:與蟒蛇DOC

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) 

回答

2

是的,你是對的。下面的代碼...

format(foo, "bar") 

調用...

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