擅长:python、mysql、java
<p>对于格式化字符串,您可能需要使用Python的<code>.format()</code>函数。看看这个问题:<a href="https://stackoverflow.com/questions/13945749/string-formatting-in-python-3">String Formatting in Python 3</a></p>
<p>在Python中格式化字符串有两种主要方法,一种是使用<code>str</code>类的<code>.format</code>方法,另一种是使用<code>%</code>符号的旧C风格方法:</p>
<p><strong>str.格式():</strong></p>
<pre><code>"This is a string with the numbers {} and {} and {0}".format(1, 2)
</code></pre>
<p><strong>C样式格式(%):</strong></p>
^{pr2}$
<p>我强烈建议不要使用C风格的格式,而是使用现代函数版本。另一种我不推荐的方法是用您自己的定义替换输入函数:</p>
<pre><code>old_input = input
def input(*args):
s = ''.join([str(a) for a in args])
return old_input(s)
input("This", "is", 1, 2, 3, "a test: ")
</code></pre>