2013-10-29 64 views
0

说我有n项目 列表我要打印的每张相继与第二之间的每个打印在列表中每个项目的其他(Python)的后一个第二

n = 5

list = [a,b,c,d,e] 

我想“打印列表”做

a 
...1 second... 
b 
..1 second... 
c 
...etc... 

我试图与计时器功能乱搞但林不知道究竟是什么做的

x = [a,b,c,d,e,f] 
for i in x 
    print x 

PS C:\PYthon\A06> python -i test.py

回答

0

使用time.sleep

>>> import time 
>>> lis = ['a', 'b', 'c', 'd', 'e'] 
>>> for x in lis: 
...  print x 
...  time.sleep(1) 
...  
a 
b 
c 
d 
e 

帮助上time.sleep

sleep(seconds) 

Delay execution for a given number of seconds. The argument may be 
a floating point number for subsecond precision. 
0

使用time.sleep() function暂停执行对于给定的时间:

import time 

x = ['a', 'b', 'c', 'd', 'e', 'f'] 

for i in x: 
    print i 
    time.sleep(1) 

time.sleep()需要一个数字参数,几秒到“睡眠”的数量。

相关问题