簡體   English   中英

依次打印列表中的每個項目(PYTHON)

[英]Print each item in list one second after the other (PYTHON)

說我有一個n項目的清單,我想一個接一個地打印,每一個之間打印一秒鍾

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

使用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幫助time.sleep

sleep(seconds)

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

使用time.sleep()函數可在給定時間內暫停執行:

import time

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

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

time.sleep()一個數字參數,即“睡眠”的秒數。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM