Why does an in-loop print() output after the loop is completed?
本问题已经有最佳答案,请猛点这里访问。
在下面的代码中,菱形字符(
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | from os import system from time import sleep def load(): system('cls') i = 0 sleep(1) print(" \t\t\t Loading", end=' ') for i in range(6): sleep(1) print("\4", end=' ') sleep(2) load() |
打印在python idle中为我工作。在windows中,
根据您的操作系统,您必须更改行尾。请查看此页面以了解更多信息:在同一行上打印python
这在Windows上工作:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | from os import system from time import sleep import sys def load(): system('cls') i = 0 sleep(1) sys.stdout.write(" \t\t\t Loading") for i in range(6): sleep(1) sys.stdout.write("\4") sys.stdout.flush() sleep(2) load() |