0

Say I have a list of n items I want to print each one after another with a second in between each

say n = 5:

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

I want "print list" to do

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

I have tried messing around with timer functions but im not sure what exactly to do

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

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

4

2 回答 2

1

Use time.sleep:

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

Help on time.sleep:

sleep(seconds)

Delay execution for a given number of seconds.  The argument may be
a floating point number for subsecond precision.
于 2013-10-29T18:39:48.157 回答
0

Use the time.sleep() function to pause execution for a given time:

import time

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

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

time.sleep() takes an numeric argument, the number of seconds to 'sleep'.

于 2013-10-29T18:39:58.467 回答