Python 如何在一行多行中打印多次?
我知道如何在一行中循环打印:Python 如何在一行多行中打印多次?,python,Python,我知道如何在一行中循环打印: array = [1, 2, 3, 4] for i in array: print("This is {}".format(i), end="") time.sleep(1) 但是如果我想要一个具有多行的输出(换行),我如何可以这样做: print("This is {} \n And this is two {}".format(i, i + 1), end="") time.sleep(1) 输出将是: This is 1 And this
array = [1, 2, 3, 4]
for i in array:
print("This is {}".format(i), end="")
time.sleep(1)
但是如果我想要一个具有多行的输出(换行),我如何可以这样做:
print("This is {} \n And this is two {}".format(i, i + 1), end="")
time.sleep(1)
输出将是:
This is 1
And this is two 2This is 2
And this is two 3This is 3
....
我想:
This is 1 #increment here in one line to 2, 3, 4..
And this is two 2 #same here 3, 4, 5..
感谢您的帮助您只需执行以下操作:
import time
array = [1, 2, 3, 4]
for i in range(len(array)):
if (i != len(array) - 1):
print("This is {}".format(array[i]), end="\nAnd ")
time.sleep(1)
else:
print("This is {}".format(array[i]))
输出:
This is 1
And This is 2
And This is 3
And This is 4
你需要使用
curses
在屏幕上移动。为什么要使用php
标记?对我来说,它看起来像是python
code。我改成了python,我的错,谢谢,但这不是重点。我需要输出仍然在一行中。我想用它来打印显示每秒变化值的图表。你能澄清一下你所说的一行是什么意思吗。你能举个例子吗?除了你现在给的