<p>我需要写入前一行的命令,例如print()而不需要</p>
<p>下面是一些示例代码:</p>
<pre><code>a=0
print("Random string value")
if a==0:
print_to_previous_line("is random")
</code></pre>
<p>和输出</p>
<pre><code>Random string value is random
</code></pre>
<p>我知道我可以像print(“string”,value)一样在同一个print命令中使用多文件不同的东西,但这不是答案。原因太混乱,无法在这里解释,但这个“打印到上一行”将是完全正确的答案。那么现实中会是什么呢?</p>
<p>我建议用打印声明,像这样</p>
<pre><code>print("This is a text",end=" ")
</code></pre>
<p>end=“”表示,字符串不是“完整的”,下一个print语句需要在同一行中。字符串“”意味着它应该在下一个print语句中在该字符串和该字符串之间留一个空格。或者您也可以使用end=。
我希望这有帮助!</p>