这个问题没有重复,链接和问题不能解决问题,我正在尝试在同一位置打印两行(每行打印一行,循环内没有新行(,链接的问题显示了如何在同一位置只打印一行......
可以使用 Python 在循环内的相同位置轻松打印一行:
from time import sleep
for i in range(50):
sleep(0.1)
print("hi"+str(i) , end="r")
但是我如何在循环中使用两条线来做到这一点呢?
我试过了:
from time import sleep
for i in range(50):
sleep(0.1)
print("hi"+str(i) , end="r")
print("hi2"+str(i) , end="r")
它不起作用:-(
我尝试(没有第一个r
(:
print("hi"+str(i) , end="")
print("hi2"+str(i) , end="r")
也不起作用,这个打印hi
和hi2
在同一行......
有一些方法可以打印hi和hi2(每个连续(保持位置线?
预期结果将是:
hi<increment from 0 to 50 without new line jump inside the loop>
hi2<increment from 0 to 50 without new line jump inside the loop>
for i in range(50):
sleep(0.1)
print("hi"+str(i))
print('hi2'+str(i), end='r')
if i<49:
print(' 33[2F') # 33[2F,escape character to move cursor to the two lines up
希望对您有所帮助