<p>我正在将%的用法转换为str.format格式(),并意识到字符串不需要位置号。例如</p>
<pre><code>>>> "We have {0} hectares planted to {1}.".format(49, "okra")
'We have 49 hectares planted to okra.'
>>> "We have {} hectares planted to {}.".format(49, "okra")
'We have 49 hectares planted to okra.'
</code></pre>
<p>什么时候应该使用这些数字,什么时候应该省略它们?如果只有一个替代品,哪种方法更清楚?在我的整个脚本中,从来没有无序的替换,所以我可以不使用数字来保持一致。你知道吗</p>
<p>我是为那些不经常掌握编程知识,但经常需要使用/调整脚本的科学家编写脚本的。你知道吗</p>