__format__方法应如何用于int? [英] How is the __format__ method supposed to be used for int?
本文介绍了__format__方法应如何用于int?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我看到有一个 __ format __
方法,但是help( int .__ format __
)没有提供任何帮助.
I saw there was a __format__
method but help(int.__format__
) doesn't provide any help.
我也知道您不应该直接调用 __ method __
.什么时候调用此方法?它的论点是什么?
I also know you're not suppose to call a __method__
directly. When is this method called? Which is its argument?
推荐答案
它用于Py3k的新字符串格式设置方案.
It's used for Py3k's new string formatting scheme.
您可以在此处找到更多信息:
You can find more info here:
http://docs.python.org/whatsnew/2.6.html#pep-3101-advanced-string-formatting
您是对的,没有直接调用它.可以通过 str.format
或内置的新 format
来调用.
You are right that it isn't called directly. It's called by str.format
or the new format
builtin.
这篇关于__format__方法应如何用于int?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文