这段代码:
import time
for i in range(10):
print(i)
time.sleep(.5)
Run Code Online (Sandbox Code Playgroud)
使我的电脑挂起5秒钟,然后打印0-9,而不是每半秒打印一个数字.难道我做错了什么?
此代码按预期工作.输出:
Loading
Loading.
Loading..
Loading...
Run Code Online (Sandbox Code Playgroud)
码:
done = False
count = 0
while not done:
print '{0}\r'.format("Loading"),
time.sleep(0.25)
print '{0}\r'.format("Loading."),
time.sleep(0.25)
print '{0}\r'.format("Loading.."),
time.sleep(0.25)
print '{0}\r'.format("Loading..."),
time.sleep(0.25)
count += 1
if count == 5:
done = True
Run Code Online (Sandbox Code Playgroud)
而这段代码没有.输出:
Loading.
Loading...
Run Code Online (Sandbox Code Playgroud)
码:
done = False
count = 0
while not done:
print '{0}\r'.format("Loading"),
time.sleep(0.125)
print '{0}\r'.format("Loading."),
time.sleep(0.125)
print '{0}\r'.format("Loading.."),
time.sleep(0.125)
print '{0}\r'.format("Loading..."),
time.sleep(0.125)
count += 1
if count == 5:
done = True
Run Code Online (Sandbox Code Playgroud)
为什么时间函数似乎跳过每一个print语句,如果它低于0.25?