gpt4 book ai didi

Python每秒增加一个数字

转载 作者:太空宇宙 更新时间:2023-11-04 10:17:41 26 4
gpt4 key购买 nike

如何每秒递增一个数字?我在想这样的事情。

import  threading

def printit():
second = 1
while threading.Timer(1, printit).start(): #for every second that pass.
print(second)
second += 1

printit()

最佳答案

我建议使用 time.sleep(1) 的不同方法,解决方案是:

from time import sleep
def printit():
... cpt = 1
... while True:
... print cpt
... sleep(1)
... cpt+=1

time.sleep(secs)

Suspend execution of the current thread for the given number of seconds.

关于Python每秒增加一个数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34400986/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com